#include <cmath> // for round
#include <cstdio> // for printf, sscanf
#include <cstdlib> // for strtod
+#include <tuple> // for tie, tuple
#include <QByteArray> // for QByteArray
#include <QString> // for QString
QString line;
gpsbabel::TextStream stream;
- stream.open(arcfileopt, QIODevice::ReadOnly, MYNAME);
+ stream.open(arcfileopt.get(), QIODevice::ReadOnly, MYNAME);
auto* arcpt1 = new Waypoint;
auto* arcpt2 = new Waypoint;
if (wp->extra_data) {
auto* ed = (extra_data*) wp->extra_data;
wp->extra_data = nullptr;
- if ((ed->distance >= pos_dist) == (exclopt == nullptr)) {
+ if ((ed->distance >= pos_dist) == !exclopt) {
wp->wpt_flags.marked_for_deletion = 1;
removed++;
} else if (projectopt) {
#ifndef ARCDIST_H_INCLUDED_
#define ARCDIST_H_INCLUDED_
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h" // for ARG_NOMINMAX, ARGTYPE_BOOL, Waypoint (ptr only)
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool, OptionCString
#if FILTERS_ENABLED
/* Data Members */
double pos_dist{};
- char* distopt = nullptr;
- char* arcfileopt = nullptr;
- char* rteopt = nullptr;
- char* trkopt = nullptr;
- char* exclopt = nullptr;
- char* ptsopt = nullptr;
- char* projectopt = nullptr;
+ OptionCString distopt;
+ OptionCString arcfileopt;
+ OptionBool rteopt;
+ OptionBool trkopt;
+ OptionBool exclopt;
+ OptionBool ptsopt;
+ OptionBool projectopt;
QVector<arglist_t> args = {
{
#ifndef BEND_H_INCLUDED_
#define BEND_H_INCLUDED_
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h" // for route_head (ptr only), ARGTYPE_FLOAT, ARG_NOMINMAX
#include "filter.h" // for Filter
+#include "option.h" // for OptionCString
#if FILTERS_ENABLED
void deinit() override;
private:
- char* distopt = nullptr;
- char* minangleopt = nullptr;
+ OptionCString distopt;
+ OptionCString minangleopt;
double maxDist{};
double minAngle{};
#include "geocache.h" // for Geocache
#include "formspec.h" // for FormatSpecificData
#include "inifile.h" // for inifile_t
+#include "option.h"
#include "session.h" // for session_t
#include "src/core/datetime.h" // for DateTime
struct arglist_t {
const QString argstring;
- char** const argval{nullptr};
+ Option* const argval{nullptr};
const QString helpstring;
const QString defaultvalue;
const uint32_t argtype{ARGTYPE_UNKNOWN};
const QString minvalue; /* minimum value for numeric options */
const QString maxvalue; /* maximum value for numeric options */
- char* argvalptr{nullptr}; /* !!! internal helper. Not used in definitions !!! */
+ char* unused{nullptr}; /* TODO: delete from initialization lists */
};
enum ff_type {
void
Dg100Format::read()
{
- if (*erase_only == '1') {
+ if (erase_only) {
dg100_erase();
return;
}
dg100_getfiles();
- if (*erase == '1') {
+ if (erase) {
dg100_erase();
}
}
#ifndef DG100_H_INCLUDED_
#define DG100_H_INCLUDED_
-#include <cstdint> // for uint8_t, int16_t, uint16_t
-#include <cstdio> // for size_t
+#include <cstdint> // for uint8_t, int16_t, uint16_t
+#include <cstdio> // for size_t
-#include <QDateTime> // for QDateTime
-#include <QList> // for QList
-#include <QString> // for QString
-#include <QVector> // for QVector
+#include <QDateTime> // for QDateTime
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h" // for Format
-#include "gbfile.h" // for gbfile
+#include "format.h" // for Format
+#include "gbfile.h" // for gbfile
+#include "option.h" // for OptionBool
class Dg100Format : public Format
/* GPSBabel integration */
- char* erase{nullptr};
- char* erase_only{nullptr};
+ OptionBool erase;
+ OptionBool erase_only;
QVector<arglist_t> dg100_args = {
{
}
if (nameopt) {
- name_regex = generateRegExp(nameopt);
+ name_regex = generateRegExp(nameopt.get());
if (!name_regex.isValid()) {
fatal(FatalMsg() << "discard: matchname option is an invalid expression.");
}
}
if (descopt) {
- desc_regex = generateRegExp(descopt);
+ desc_regex = generateRegExp(descopt.get());
if (!desc_regex.isValid()) {
fatal(FatalMsg() << "discard: matchdesc option is an invalid expression.");
}
}
if (cmtopt) {
- cmt_regex = generateRegExp(cmtopt);
+ cmt_regex = generateRegExp(cmtopt.get());
if (!cmt_regex.isValid()) {
fatal(FatalMsg() << "discard: matchcmt option is an invalid expression.");
}
}
if (iconopt) {
- icon_regex = generateRegExp(iconopt);
+ icon_regex = generateRegExp(iconopt.get());
if (!icon_regex.isValid()) {
fatal(FatalMsg() << "discard: matchicon option is an invalid expression.");
}
#ifndef DISCARD_H_INCLUDED_
#define DISCARD_H_INCLUDED_
+#include <QList> // for QList
#include <QRegularExpression> // for QRegularExpression
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h" // for arglist_t, ARG_NOMINMAX, ARGTYPE_BEGIN_REQ, ARGTYPE_STRING, ARGTYPE_BOOL, ARGTYPE_INT, ARGTYPE_FLOAT, route_head, ARGTYPE_END_REQ, Waypoint, gpsdata_type
#include "filter.h" // for Filter
+#include "option.h" // for OptionCString, OptionBool
#if FILTERS_ENABLED
class DiscardFilter:public Filter
/* Data Members */
- char* hdopopt = nullptr;
- char* vdopopt = nullptr;
- char* andopt = nullptr;
- char* satopt = nullptr;
- char* fixnoneopt = nullptr;
- char* fixunknownopt = nullptr;
- char* eleminopt = nullptr;
- char* elemaxopt = nullptr;
- char* nameopt = nullptr;
+ OptionCString hdopopt;
+ OptionCString vdopopt;
+ OptionBool andopt;
+ OptionCString satopt;
+ OptionBool fixnoneopt;
+ OptionBool fixunknownopt;
+ OptionCString eleminopt;
+ OptionCString elemaxopt;
+ OptionCString nameopt;
QRegularExpression name_regex;
- char* descopt = nullptr;
+ OptionCString descopt;
QRegularExpression desc_regex;
- char* cmtopt = nullptr;
+ OptionCString cmtopt;
QRegularExpression cmt_regex;
- char* iconopt = nullptr;
+ OptionCString iconopt;
QRegularExpression icon_regex;
double hdopf{};
#ifndef DUPLICATE_H_INCLUDED_
#define DUPLICATE_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, Waypoint (ptr only)
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool
#if FILTERS_ENABLED
void process() override;
private:
- char* snopt = nullptr;
- char* lcopt = nullptr;
- char* purge_duplicates = nullptr;
- char* correct_coords = nullptr;
+ OptionBool snopt;
+ OptionBool lcopt;
+ OptionBool purge_duplicates;
+ OptionBool correct_coords;
QVector<arglist_t> args = {
{
{
if (exif_wpt_ref != nullptr) {
return;
- } else if ((wpt->shortname != nullptr) && (case_ignore_strcmp(wpt->shortname, opt_name) == 0)) {
+ } else if ((wpt->shortname != nullptr) && (case_ignore_strcmp(wpt->shortname, opt_name.get()) == 0)) {
exif_wpt_ref = wpt;
}
}
gbfclose(fout_);
if (exif_success) {
- if (*opt_overwrite == '1') {
+ if (opt_overwrite) {
QFile::remove(exif_fout_name);
QFile::rename(tmpname, exif_fout_name);
}
track_disp_all(nullptr, nullptr, exif_find_wpt_by_name_lambda);
}
if (exif_wpt_ref == nullptr) {
- warning(MYNAME ": No matching point with name \"%s\" found.\n", opt_name);
+ warning(MYNAME ": No matching point with name \"%s\" found.\n", qPrintable(opt_name.get()));
}
} else {
auto exif_find_wpt_by_time_lambda = [this](const Waypoint* waypointp)->void {
#ifndef EXIF_H_INCLUDED_
#define EXIF_H_INCLUDED_
-#include <QDate> // for QDate
-#include <QDateTime> // for QDateTime
-#include <QList> // for QList
-#include <QString> // for QString
-#include <QTime> // for QTime
-#include <QVariant> // for QVariant
-#include <QVector> // for QVector
+#include <QByteArray> // for QByteArray
+#include <QDate> // for QDate
+#include <QDateTime> // for QDateTime
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QTime> // for QTime
+#include <QVariant> // for QVariant
+#include <QVector> // for QVector
-#include <cstdint> // for uint32_t, uint16_t, uint8_t, int16_t, int32_t
+#include <cstdint> // for uint32_t, uint16_t, uint8_t, int16_t, int32_t
-#include "defs.h" // for arglist_t, ff_cap, Waypoint, ARG_NOMINMAX, ARGTYPE_BOOL, ff_cap_none, ARGTYPE_INT, ARGTYPE_STRING, ff_cap_read, ff_cap_write, ff_type, ff_type_file
-#include "format.h" // for Format
-#include "gbfile.h" // for gbfile, gbsize_t
+#include "defs.h" // for arglist_t, ff_cap, Waypoint, ARG_NOMINMAX, ARGTYPE_BOOL, ff_cap_none, ARGTYPE_INT, ARGTYPE_STRING, ff_cap_read, ff_cap_write, ff_type, ff_type_file
+#include "format.h" // for Format
+#include "gbfile.h" // for gbfile, gbsize_t
+#include "option.h" // for OptionCString, OptionBool
class ExifFormat : public Format
char exif_success{};
QString exif_fout_name;
- char* opt_filename{};
- char* opt_overwrite{};
- char* opt_frame{};
- char* opt_name{};
- char* opt_offsettime{};
+ OptionBool opt_filename;
+ OptionBool opt_overwrite;
+ OptionCString opt_frame;
+ OptionCString opt_name;
+ OptionCString opt_offsettime;
QVector<arglist_t> exif_args = {
{ "filename", &opt_filename, "Set waypoint name to source filename", "Y", ARGTYPE_BOOL, ARG_NOMINMAX, nullptr },
#include <algorithm> // for sort
#include <cassert> // for assert
#include <cstdio> // for printf
+#include <type_traits> // for is_base_of
#include "arcdist.h" // for ArcDistanceFilter
#include "bend.h" // for BendFilter
qtemp = inifile_readstr(global_opts.inifile, "Common filter settings", arg.argstring);
}
if (qtemp.isNull()) {
- Vecs::assign_option(fltdata.fltname, &arg, arg.defaultvalue);
+ Vecs::assign_option(fltdata.fltname, arg, arg.defaultvalue);
} else {
- Vecs::assign_option(fltdata.fltname, &arg, qtemp);
+ Vecs::assign_option(fltdata.fltname, arg, qtemp);
}
}
}
for (auto& arg : *args) {
const QString opt = Vecs::get_option(fltdata.options, arg.argstring);
if (!opt.isNull()) {
- Vecs::assign_option(fltdata.fltname, &arg, opt);
+ Vecs::assign_option(fltdata.fltname, arg, opt);
}
}
}
QVector<arglist_t>* args = flt->get_args();
if (args && !args->isEmpty()) {
assert(args->isDetached());
- for (auto& arg : *args) {
- arg.argvalptr = nullptr;
- }
}
}
#ifndef FILTER_VECS_H_INCLUDED_
#define FILTER_VECS_H_INCLUDED_
-#include <QString> // for QString
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QStringList> // for QStringList
-#include "defs.h" // for arglist_t
-#include "filter.h" // for Filter
+#include "defs.h" // for arglist_t
+#include "filter.h" // for Filter
class FilterVecs
case 786: /* HC model */
case 957: /* Legend HC */
receiver_short_length = 14;
- snwhiteopt = xstrdup("1");
+ snwhiteopt.set("1");
receiver_must_upper = false;
/* This might be 8859-1 */
receiver_charset = "windows-1252";
mkshort_handle->set_length(receiver_short_length);
}
- if (snwhiteopt) {
- mkshort_handle->set_whitespace_ok(xstrtoi(snwhiteopt, nullptr, 10));
+ if (snwhiteopt.has_value()) {
+ mkshort_handle->set_whitespace_ok(snwhiteopt);
}
/*
tx_waylist[i]->lat = wpt->latitude;
if (deficon) {
- icon = gt_find_icon_number_from_desc(deficon, PCX);
+ icon = gt_find_icon_number_from_desc(deficon.get(), PCX);
} else {
if (!wpt->gc_data->get_icon().isEmpty()) {
icon = gt_find_icon_number_from_desc(wpt->gc_data->get_icon(), PCX);
#ifndef GARMIN_H_INCLUDED_
#define GARMIN_H_INCLUDED_
-#include <cstdio> // for size_t
+#include <cstdio> // for size_t
-#include <QByteArray> // for QByteArray
-#include <QString> // for QString
-#include <QTextCodec> // for QTextCodec
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QByteArray> // for QByteArray
+#include <QString> // for QString
+#include <QTextCodec> // for QTextCodec
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h" // for Format
-#include "jeeps/gpsdevice.h" // for gpsdevh
-#include "jeeps/gpssend.h" // for GPS_PWay, GPS_SWay, GPS_PTrack, GPS_PPvt_Data, GPS_SLap
-#include "mkshort.h" // for MakeShort
+#include "format.h" // for Format
+#include "jeeps/gpsdevice.h" // for gpsdevh
+#include "jeeps/gpssend.h" // for GPS_PWay, GPS_SWay, GPS_PTrack, GPS_PPvt_Data, GPS_SLap
+#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionCString, OptionBool
class GarminFormat : public Format
GPS_PTrack* tx_tracklist{};
GPS_PTrack* cur_tx_tracklist_entry{};
int my_track_count = 0;
- char* getposn = nullptr;
- char* poweroff = nullptr;
- char* eraset = nullptr;
- char* resettime = nullptr;
- char* snlen = nullptr;
- char* snwhiteopt = nullptr;
- char* deficon = nullptr;
- char* category = nullptr;
- char* categorybitsopt = nullptr;
- char* baudopt = nullptr;
- char* opt_codec = nullptr;
+ OptionBool getposn;
+ OptionBool poweroff;
+ OptionBool eraset;
+ OptionBool resettime;
+ OptionCString snlen;
+ OptionBool snwhiteopt;
+ OptionCString deficon;
+ OptionCString category;
+ OptionCString categorybitsopt;
+ OptionCString baudopt;
+ OptionCString opt_codec;
int baud = 0;
int categorybits{};
bool receiver_must_upper = true;
#include <cstdint> // for uint8_t, uint16_t, uint32_t, int32_t, int8_t, uint64_t
#include <cstdio> // for EOF, SEEK_SET, snprintf
#include <deque> // for deque, _Deque_iterator, operator!=
-#include <memory> // for allocator_traits<>::value_type
#include <string> // for operator+, to_string, char_traits
#include <utility> // for pair
#include <vector> // for vector
#include "defs.h"
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
+#include "option.h" // for OptionBool
#include "src/core/datetime.h" // for DateTime
/* Data Members */
- char* opt_allpoints = nullptr;
- char* opt_recoverymode = nullptr;
+ OptionBool opt_allpoints;
+ OptionBool opt_recoverymode;
int lap_ct = 0;
bool new_trkseg = false;
bool write_header_msgs = false;
{
int sz = wdata_compute_size(wdata);
sz += 8; /* string header */
- sz += str_from_unicode(QString::fromUtf8(opt_cat)).size();
+ sz += str_from_unicode(opt_cat.get()).size();
gbfputint32(0x80009, fout);
if ((! opt_hide_bitmap) && image_sz) {
gbfputint32(sz, fout);
}
gbfputint32(sz, fout);
- write_string(str_from_unicode(QString::fromUtf8(opt_cat)), 1);
+ write_string(str_from_unicode(opt_cat.get()), 1);
wdata_write(wdata);
auto* wpt = new Waypoint(*ref);
- if (*opt_unique == '1') {
+ if (opt_unique) {
wpt->shortname = short_h->mkshort(wpt->shortname);
}
}
if (! codepage) {
- warning(MYNAME ": Unsupported character set (%s)!\n", opt_writecodec);
+ warning(MYNAME ": Unsupported character set (%s)!\n", qPrintable(opt_writecodec.get()));
fatal(MYNAME ": Valid values are windows-1250 to windows-1257 and utf8.\n");
}
- codec = get_codec(opt_writecodec);
+ codec = get_codec(opt_writecodec.getba());
units = tolower(opt_units[0]);
if ((units != 'm') && (units != 's')) {
#include "garmin_fs.h" // for garmin_fs_t
#include "gbfile.h" // for gbfile
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionCString, OptionBool
class GarminGPIFormat : public Format
/* Data Members */
- char* opt_cat{}, *opt_pos{}, *opt_notes{}, *opt_hide_bitmap{}, *opt_descr{}, *opt_bitmap{};
- char* opt_unique{}, *opt_alerts{}, *opt_units{}, *opt_speed{}, *opt_proximity{}, *opt_sleep{};
- char* opt_lang{};
- char* opt_writecodec{};
+ OptionCString opt_cat;
+ OptionBool opt_pos;
+ OptionBool opt_notes;
+ OptionBool opt_hide_bitmap;
+ OptionBool opt_descr;
+ OptionCString opt_bitmap;
+ OptionBool opt_unique;
+ OptionBool opt_alerts;
+ OptionCString opt_units;
+ OptionCString opt_speed;
+ OptionCString opt_proximity;
+ OptionCString opt_sleep;
+ OptionCString opt_lang;
+ OptionCString opt_writecodec;
double defspeed{}, defproximity{};
int alerts{};
GarminTxtFormat::garmin_txt_utc_option()
{
if (opt_utc != nullptr) {
- if (case_ignore_strcmp(opt_utc, "utc") == 0) {
+ if (case_ignore_strcmp(opt_utc.get(), "utc") == 0) {
utc_offs = 0;
} else {
utc_offs = xstrtoi(opt_utc, nullptr, 10);
if (opt_precision) {
precision = xstrtoi(opt_precision, nullptr, 10);
if (precision < 0) {
- fatal(MYNAME ": Invalid precision (%s)!", opt_precision);
+ fatal(MYNAME ": Invalid precision (%s)!", qPrintable(opt_precision.get()));
}
}
#include "defs.h"
#include "format.h" // for Format
+#include "option.h" // for OptionCString
#include "src/core/textstream.h" // for TextStream
std::array<QList<std::pair<QString, int>>, unknown_header> header_mapping_info;
QStringList header_column_names;
- char* opt_datum = nullptr;
- char* opt_dist = nullptr;
- char* opt_temp = nullptr;
- char* opt_date_format = nullptr;
- char* opt_time_format = nullptr;
- char* opt_precision = nullptr;
- char* opt_utc = nullptr;
- char* opt_grid = nullptr;
+ OptionCString opt_datum;
+ OptionCString opt_dist;
+ OptionCString opt_temp;
+ OptionCString opt_date_format;
+ OptionCString opt_time_format;
+ OptionCString opt_precision;
+ OptionCString opt_utc;
+ OptionCString opt_grid;
QVector<arglist_t> garmin_txt_args = {
{"date", &opt_date_format, "Read/Write date format (i.e. yyyy/mm/dd)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr},
#include <cstdint> // for uint8_t, uint16_t, uint32_t
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h"
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
+#include "option.h" // for OptionCString
class GarminXTFormat : public Format
gbfile* fin{};
route_head* track{};
- char* opt_xt_ftype = nullptr;
- char* opt_trk_header = nullptr;
+ OptionCString opt_xt_ftype;
+ OptionCString opt_trk_header;
QVector<arglist_t> format_garmin_xt_args = {
{"ftype", &opt_xt_ftype, "Garmin Mobile XT ([ATRK]/STRK)", "ATRK", ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr},
#ifndef GDB_H_INCLUDED_
#define GDB_H_INCLUDED_
+#include <QList> // for QList
#include <QHash> // for QHash<>::const_iterator, QHash<>::key_iterator, qHash, qHashMulti, QHash
#include <QString> // for QString
#include <QStringView> // for QStringView
#include "garmin_tables.h" // for gt_waypt_classes_e
#include "gbfile.h" // for gbfile
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionBool, OptionCString
class GdbFormat : public Format
WptNamePosnHash waypt_nameposn_out_hash;
MakeShort* short_h{};
- char* gdb_opt_category{};
- char* gdb_opt_ver{};
- char* gdb_opt_via{};
- char* gdb_opt_roadbook{};
- char* gdb_opt_bitcategory{};
- char* gdb_opt_drop_hidden_wpt{};
+ OptionCString gdb_opt_category;
+ OptionCString gdb_opt_ver;
+ OptionBool gdb_opt_via;
+ OptionBool gdb_opt_roadbook;
+ OptionCString gdb_opt_bitcategory;
+ OptionBool gdb_opt_drop_hidden_wpt;
int waypt_flag{};
int route_flag{};
writer.writeAttribute(QStringLiteral("lon"), QString::number(waypointp->longitude, 'f'));
writer.writeEndElement();
- writer.writeTextElement(QStringLiteral("type"), deficon ? deficon : waypointp->icon_descr);
+ writer.writeTextElement(QStringLiteral("type"), deficon ? deficon.get() : waypointp->icon_descr);
if (waypointp->HasUrlLink()) {
writer.writeStartElement(QStringLiteral("link"));
#include "defs.h"
#include "format.h" // for Format
#include "geocache.h" // for Geocache, Geocache::container_t
+#include "option.h" // for OptionBool, OptionCString
class GeoFormat : public Format
/* Data Members */
- char* deficon = nullptr;
- char* nuke_placer{};
+ OptionCString deficon;
+ OptionBool nuke_placer;
QVector<arglist_t> geo_args = {
{"deficon", &deficon, "Default icon name", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr },
#ifndef GEOJSON_H_INCLUDED_
#define GEOJSON_H_INCLUDED_
-#include <QJsonArray> // for QJsonArray
-#include <QJsonObject> // for QJsonObject
-#include <QString> // for QString, QStringLiteral
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QJsonArray> // for QJsonArray
+#include <QJsonObject> // for QJsonObject
+#include <QString> // for QString, QStringLiteral
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h" // for Format
-#include "src/core/file.h"
+#include "format.h" // for Format
+#include "option.h" // for OptionBool
+#include "src/core/file.h" // for File
class GeoJsonFormat : public Format
{
gpsbabel::File* ifd{nullptr};
gpsbabel::File* ofd{nullptr};
const char* MYNAME = "geojson";
- char* compact_opt = nullptr;
+ OptionBool compact_opt;
QJsonObject* track_object = nullptr;
QJsonArray* track_coords = nullptr;
printf(MYNAME " rd_init()\n");
}
if (opt_dump_file) {
- dumpfile = gbfopen(opt_dump_file, "wb", MYNAME);
+ dumpfile = gbfopen(opt_dump_file.get(), "wb", MYNAME);
if (!dumpfile) {
- printf(MYNAME " rd_init() creating dumpfile %s FAILED continue anyway\n", opt_dump_file);
+ printf(MYNAME " rd_init() creating dumpfile %s FAILED continue anyway\n", qPrintable(opt_dump_file.get()));
} else {
if (global_opts.debug_level > 1) {
- printf(MYNAME " rd_init() creating dumpfile %s for writing binary copy of serial stream\n", opt_dump_file);
+ printf(MYNAME " rd_init() creating dumpfile %s for writing binary copy of serial stream\n", qPrintable(opt_dump_file.get()));
}
}
}
}
if (opt_timezone) {
- if (QTimeZone::isTimeZoneIdAvailable(opt_timezone)) {
- timezn = new QTimeZone(opt_timezone);
+ if (QTimeZone::isTimeZoneIdAvailable(opt_timezone.getba())) {
+ timezn = new QTimeZone(opt_timezone.getba());
} else {
list_timezones();
- fatal(MYNAME ": Requested time zone \"%s\" not available.\n", opt_timezone);
+ fatal(MYNAME ": Requested time zone \"%s\" not available.\n", qPrintable(opt_timezone.get()));
}
} else {
timezn = nullptr;
#ifndef GLOBALSATSPORT_H_INCLUDED_
#define GLOBALSATSPORT_H_INCLUDED_
-#include <cstdint> // for uint32_t, uint8_t, uint16_t, int16_t
+#include <cstdint> // for uint32_t, uint8_t, uint16_t, int16_t
-#include <QString> // for QString
-#include <QTimeZone> // for QTimeZone
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QTimeZone> // for QTimeZone
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h" // for Format
-#include "gbfile.h" // for gbfclose, gbfopen, gbfread, gbfwrite, gbfile
+#include "format.h" // for Format
+#include "gbfile.h" // for gbfclose, gbfopen, gbfread, gbfwrite, gbfile
+#include "option.h" // for OptionCString, OptionBool
class GlobalsatSportFormat : public Format
void* serial_handle{nullptr};
bool isSizeSwapped{false};
- char* showlist{nullptr}; // if true show a list instead of download tracks
- char* track{nullptr}; // if not 0 only download this track, if 0 download all
+ OptionBool showlist; // if true show a list instead of download tracks
+ OptionCString track; // if not 0 only download this track, if 0 download all
- char* opt_dump_file{nullptr}; // dump raw data to this file (optional)
- char* opt_input_dump_file{nullptr}; // if true input is from a dump-file instead of serial console
- char* opt_timezone{nullptr};
+ OptionCString opt_dump_file; // dump raw data to this file (optional)
+ OptionBool opt_input_dump_file; // if true input is from a dump-file instead of serial console
+ OptionCString opt_timezone;
gbfile* dumpfile{nullptr}; // used for creating bin/RAW datadump files, useful for testing
gbfile* in_file{nullptr}; // used for reading from bin/RAW datadump files, useful for testing
QTimeZone* timezn{nullptr};
*/
if (opt_gpxver != nullptr) {
- gpx_write_version = QVersionNumber::fromString(opt_gpxver).normalized();
+ gpx_write_version = QVersionNumber::fromString(opt_gpxver.get()).normalized();
} else if (!gpx_highest_version_read.isNull()) {
gpx_write_version = gpx_highest_version_read;
} else {
#include "format.h" // for Format
#include "formspec.h" // for FormatSpecificData
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionBool, OptionCString
#include "src/core/file.h" // for File
#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter
#include "src/core/xmltag.h" // for xml_tag
QXmlStreamReader* reader{};
XmlTag* cur_tag{};
QString cdatastr;
- char* opt_logpoint = nullptr;
- char* opt_humminbirdext = nullptr;
- char* opt_garminext = nullptr;
- char* opt_elevation_precision = nullptr;
+ OptionBool opt_logpoint;
+ OptionBool opt_humminbirdext;
+ OptionBool opt_garminext;
+ OptionCString opt_elevation_precision;
int logpoint_ct = 0;
int elevation_precision{};
const QVersionNumber gpx_1_0 = QVersionNumber(1,0).normalized();
const QVersionNumber gpx_1_1 = QVersionNumber(1,1).normalized();
QVersionNumber gpx_highest_version_read;
- char* opt_gpxver = nullptr;
+ OptionCString opt_gpxver;
QVersionNumber gpx_write_version;
QXmlStreamAttributes gpx_namespace_attribute;
QString link_type;
- char* snlen = nullptr;
- char* suppresswhite = nullptr;
- char* urlbase = nullptr;
+ OptionCString snlen;
+ OptionBool suppresswhite;
+ OptionCString urlbase;
route_head* trk_head{};
route_head* rte_head{};
const route_head* current_trk_head{}; // Output.
if (opt_sport) {
for (unsigned int i = 0; i < std::size(gtc_sportlist); i++) {
- if (0 == case_ignore_strncmp(opt_sport, gtc_sportlist[i], 2)) {
+ if (0 == case_ignore_strncmp(opt_sport.get(), gtc_sportlist[i], 2)) {
gtc_sport = i;
break;
}
}
}
- gtc_course_flag = xstrtoi(opt_course, nullptr, 10);
+ gtc_course_flag = opt_course;
}
void
#include "defs.h" // for arglist_t, ff_cap, route_head, Waypoint, computed_trkdata, ARG_NOMINMAX, ff_cap_read, ARGTYPE_BOOL, ARGTYPE_STRING, ff_cap_none, ff_cap_write, ff_type, ff_type_file
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
+#include "option.h" // for OptionBool, OptionCString
#include "src/core/datetime.h" // for DateTime
#include "xmlgeneric.h" // for cb_cdata, xg_functor_map_entry, cb_start, cb_end
double gtc_end_lat{};
double gtc_end_long{};
- char* opt_sport{};
- char* opt_course{};
+ OptionCString opt_sport;
+ OptionBool opt_course;
QVector<arglist_t> gtc_args = {
{
waypointp->altitude += addf;
}
- if (wgs84tomslopt != nullptr) {
+ if (wgs84tomslopt) {
waypointp->altitude -= wgs84_separation(waypointp->latitude, waypointp->longitude);
}
}
#ifndef HEIGHT_H_INCLUDED_
#define HEIGHT_H_INCLUDED_
-#include <cstdint> // for int8_t in heightgrid.h
+#include <cstdint> // for int8_t in heightgrid.h
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
-#include "defs.h" // for arglist_t, ARG_NOMINMAX, ARGTYPE_BEGIN_REQ, ARGTYPE_BOOL, ARGTYPE_END_REQ, ARGTYPE_FLOAT, Waypoint
-#include "filter.h" // for Filter
+#include "defs.h" // for arglist_t, ARG_NOMINMAX, ARGTYPE_BEGIN_REQ, ARGTYPE_BOOL, ARGTYPE_END_REQ, ARGTYPE_FLOAT, Waypoint
+#include "filter.h" // for Filter
+#include "option.h" // for OptionBool, OptionCString
#if FILTERS_ENABLED
void process() override;
private:
- char* addopt = nullptr;
- char* wgs84tomslopt = nullptr;
+ OptionCString addopt;
+ OptionBool wgs84tomslopt;
double addf{};
// include static constexpr data member definitions with intializers for grid as private members.
#include "heightgrid.h"
#ifndef HTML_H_INCLUDED_
#define HTML_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h"
#include "format.h" // for Format
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionCString, OptionBool
#include "src/core/textstream.h" // for TextStream
int waypoint_number{};
- char* stylesheet = nullptr;
- char* html_encrypt = nullptr;
- char* includelogs = nullptr;
- char* degformat = nullptr;
- char* altunits = nullptr;
+ OptionCString stylesheet;
+ OptionBool html_encrypt;
+ OptionBool includelogs;
+ OptionCString degformat;
+ OptionCString altunits;
QVector<arglist_t> html_args = {
{
igc_ext_type_t ext = get_ext_type(ext_type);
if (ext != igc_ext_type_t::ext_rec_unknown) {
supported_extensions.append(name);
- bool enabled = **ext_option_map.value(ext) == '1';
+ bool enabled = *ext_option_map.value(ext);
if (enabled) {
int factor = get_ext_factor(ext);
ext_types_list.append(std::make_tuple(name, ext, begin, len, factor));
if (strcmp(timeadj, "auto") == 0) {
time_adj = correlate_tracks(pres_track, gnss_track);
} else if (sscanf(timeadj, "%d", &time_adj) != 1) {
- fatal(MYNAME ": bad timeadj argument '%s'\n", timeadj);
+ fatal(MYNAME ": bad timeadj argument '%s'\n", qPrintable(timeadj.get()));
}
} else {
time_adj = 0;
#ifndef IGC_H_INCLUDED_
#define IGC_H_INCLUDED_
-#include <optional> // for optional
-#include <QByteArray> // for QByteArray
-#include <QDateTime> // for QDateTime
-#include <QList> // for QList<>::const_iterator
-#include <QString> // for QString, operator+, QStringLiteral
-#include <QVector> // for QVector
-#include <QHash> // for QHash
+#include <optional> // for optional
+
+#include <QByteArray> // for QByteArray
+#include <QDateTime> // for QDateTime
+#include <QList> // for QList<>::const_iterator
+#include <QString> // for QString, operator+, QStringLiteral
+#include <QVector> // for QVector
+#include <QHash> // for QHash
#include "defs.h"
-#include "format.h" // for Format
-#include "formspec.h" // for FormatSpecificData, kFsIGC
-#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfgetstr, gbfile
-#include "src/core/datetime.h" // for DateTime
-#include "kml.h" // for wp_field
+#include "format.h" // for Format
+#include "formspec.h" // for FormatSpecificData, kFsIGC
+#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfgetstr, gbfile
+#include "kml.h" // for wp_field
+#include "option.h" // for OptionBool, OptionCString
+#include "src/core/datetime.h" // for DateTime
/*
* Notes on IGC extensions:
rec_bad = 1, // Bad record
};
- char* opt_enl{nullptr};
- char* opt_tas{nullptr};
- char* opt_vat{nullptr};
- char* opt_oat{nullptr};
- char* opt_trt{nullptr};
- char* opt_gsp{nullptr};
- char* opt_fxa{nullptr};
- char* opt_siu{nullptr};
- char* opt_acz{nullptr};
- char* opt_gfo{nullptr};
-
- const QHash<igc_ext_type_t, char**> ext_option_map = {
+ OptionBool opt_enl;
+ OptionBool opt_tas;
+ OptionBool opt_vat;
+ OptionBool opt_oat;
+ OptionBool opt_trt;
+ OptionBool opt_gsp;
+ OptionBool opt_fxa;
+ OptionBool opt_siu;
+ OptionBool opt_acz;
+ OptionBool opt_gfo;
+
+ const QHash<igc_ext_type_t, OptionBool*> ext_option_map = {
{igc_ext_type_t::ext_rec_enl, &opt_enl},
{igc_ext_type_t::ext_rec_tas, &opt_tas},
{igc_ext_type_t::ext_rec_vat, &opt_vat},
gbfile* file_out{};
char manufacturer[4] {};
const route_head* head{};
- char* timeadj = nullptr;
+ OptionCString timeadj;
QVector<arglist_t> igc_args = {
{
void InterpolateFilter::process()
{
- if (((opt_route != nullptr) && (route_count() == 0)) || ((opt_route == nullptr) && (track_count() == 0))) {
+ if ((opt_route && (route_count() == 0)) || (!opt_route && (track_count() == 0))) {
fatal(FatalMsg() << MYNAME ": Found no routes or tracks to operate on.");
}
auto process_rte_lambda = [this](const route_head* rte)->void {
process_rte(const_cast<route_head*>(rte));
};
- if (opt_route != nullptr) {
+ if (opt_route) {
route_disp_all(process_rte_lambda, nullptr, nullptr);
} else {
track_disp_all(process_rte_lambda, nullptr, nullptr);
{
// Steal all the wpts
WaypointList wptlist;
- if (opt_route != nullptr) {
+ if (opt_route) {
route_swap_wpts(rte, wptlist);
} else {
track_swap_wpts(rte, wptlist);
} else {
wpt_new->altitude = unknown_alt;
}
- if (opt_route != nullptr) {
+ if (opt_route) {
route_add_wpt(rte, wpt_new);
} else {
track_add_wpt(rte, wpt_new);
}
}
}
- if (opt_route != nullptr) {
+ if (opt_route) {
route_add_wpt(rte, wpt);
} else {
track_add_wpt(rte, wpt);
char* fm;
if ((opt_time != nullptr) && (opt_dist != nullptr)) {
fatal(FatalMsg() << MYNAME ": Can't interpolate on both time and distance.");
- } else if ((opt_time != nullptr) && (opt_route != nullptr)) {
+ } else if ((opt_time != nullptr) && opt_route) {
fatal(FatalMsg() << MYNAME ": Can't interpolate routes on time.");
} else if (opt_time != nullptr) {
max_time_step = 1000 * strtod(opt_time, nullptr); // milliseconds
#ifndef INTERPOLATE_H_INCLUDED_
#define INTERPOLATE_H_INCLUDED_
-#include <QString> // for QString
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
-#include "defs.h" // for ARG_NOMINMAX, arglist_t, ARGTYPE_BEGIN_EXCL, ARG...
-#include "filter.h" // for Filter
+#include "defs.h" // for ARG_NOMINMAX, arglist_t, ARGTYPE_BEGIN_EXCL, ARG...
+#include "filter.h" // for Filter
+#include "option.h" // for OptionCString, OptionBool
#if FILTERS_ENABLED
/* Data Members */
- char* opt_time{nullptr};
+ OptionCString opt_time;
double max_time_step{0};
- char* opt_dist{nullptr};
+ OptionCString opt_dist;
double max_dist_step{0};
- char* opt_route{nullptr};
+ OptionBool opt_route;
QVector<arglist_t> args = {
{
unitsformatter->setunits(UnitsFormatter::units_t::aviation);
break;
default:
- fatal("Units argument '%s' should be 's' for statute units, 'm' for metric, 'n' for nautical or 'a' for aviation.\n", opt_units);
+ fatal("Units argument '%s' should be 's' for statute units, 'm' for metric, 'n' for nautical or 'a' for aviation.\n", qPrintable(opt_units.get()));
break;
}
/*
}
-void KmlFormat::kml_output_linestyle(char* /*color*/, int width) const
+void KmlFormat::kml_output_linestyle(const QString& color, int width) const
{
// Style settings for line strings
writer->writeStartElement(QStringLiteral("LineStyle"));
- writer->writeTextElement(QStringLiteral("color"), opt_line_color);
+ writer->writeTextElement(QStringLiteral("color"), color);
writer->writeTextElement(QStringLiteral("width"), QString::number(width));
writer->writeEndElement(); // Close LineStyle tag
}
}
if (is_multitrack) {
- kml_output_linestyle(opt_line_color,
+ kml_output_linestyle(opt_line_color.get(),
highlighted ? line_width + 2 :
line_width);
}
if (export_points) {
writer->writeStartElement(QStringLiteral("Placemark"));
- if (xstrtoi(opt_labels, nullptr, 10)) {
+ if (opt_labels) {
writer->writeOptionalTextElement(QStringLiteral("name"), waypointp->shortname);
}
writer->writeEmptyElement(QStringLiteral("snippet"));
writer->writeStartElement(QStringLiteral("Style"));
writer->writeStartElement(QStringLiteral("IconStyle"));
writer->writeStartElement(QStringLiteral("Icon"));
- writer->writeTextElement(QStringLiteral("href"), opt_deficon);
+ writer->writeTextElement(QStringLiteral("href"), opt_deficon.get());
writer->writeEndElement(); // Close Icon tag
writer->writeEndElement(); // Close IconStyle tag
writer->writeEndElement(); // Close Style tag
kml_step_color();
writer->writeTextElement(QStringLiteral("color"), QStringLiteral("%1%2")
.arg(kml_color_sequencer.color.opacity, 2, 16, QChar('0')).arg(kml_color_sequencer.color.bbggrr, 6, 16, QChar('0')));
- writer->writeTextElement(QStringLiteral("width"), opt_line_width);
+ writer->writeTextElement(QStringLiteral("width"), opt_line_width.get());
} else {
if (header->line_color.bbggrr >= 0) {
writer->writeTextElement(QStringLiteral("color"), QStringLiteral("%1%2")
kml_output_timestamp(waypointp);
// Icon - but only if it looks like a URL.
- icon = opt_deficon ? opt_deficon : waypointp->icon_descr;
+ icon = opt_deficon ? opt_deficon.get() : waypointp->icon_descr;
if (icon.contains("://")) {
writer->writeStartElement(QStringLiteral("Style"));
writer->writeStartElement(QStringLiteral("IconStyle"));
void KmlFormat::write()
{
// Parse options
- export_lines = (0 == strcmp("1", opt_export_lines));
- export_points = (0 == strcmp("1", opt_export_points));
- export_track = (0 == strcmp("1", opt_export_track));
- floating = (!! strcmp("0", opt_floating));
- extrude = (!! strcmp("0", opt_extrude));
+ export_lines = opt_export_lines;
+ export_points = opt_export_points;
+ export_track = opt_export_track;
+ floating = opt_floating;
+ extrude = opt_extrude;
rotate_colors = (!! opt_rotate_colors);
- trackdata = (!! strcmp("0", opt_trackdata));
- trackdirection = (!! strcmp("0", opt_trackdirection));
+ trackdata = opt_trackdata;
+ trackdirection = opt_trackdirection;
line_width = xstrtoi(opt_line_width, nullptr, 10);
precision = xstrtoi(opt_precision, nullptr, 10);
if (track_waypt_count() || route_waypt_count()) {
writer->writeStartElement(QStringLiteral("Style"));
writer->writeAttribute(QStringLiteral("id"), QStringLiteral("lineStyle"));
- kml_output_linestyle(opt_line_color, line_width);
+ kml_output_linestyle(opt_line_color.get(), line_width);
writer->writeEndElement(); // Close Style tag
}
#include "defs.h"
#include "format.h"
+#include "option.h" // for OptionBool, OptionCString
#include "src/core/datetime.h" // for DateTime
#include "src/core/file.h" // for File
#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter
void gx_trk_e(const QString& args, const QXmlStreamAttributes* attrs);
void gx_trk_when(const QString& args, const QXmlStreamAttributes* attrs);
void gx_trk_coord(const QString& args, const QXmlStreamAttributes* attrs);
- void kml_output_linestyle(char* color, int width) const;
+ void kml_output_linestyle(const QString& color, int width) const;
void kml_write_bitmap_style_(const QString& style, const QString& bitmap, bool highlighted, bool force_heading) const;
void kml_write_bitmap_style(kml_point_type pt_type, const QString& bitmap, const QString& customstyle) const;
void kml_output_timestamp(const Waypoint* waypointp) const;
QHash<const route_head*, track_trait_t> kml_track_traits_hash;
// options
- char* opt_deficon{nullptr};
- char* opt_export_lines{nullptr};
- char* opt_export_points{nullptr};
- char* opt_export_track{nullptr};
- char* opt_line_width{nullptr};
- char* opt_line_color{nullptr};
- char* opt_floating{nullptr};
- char* opt_extrude{nullptr};
- char* opt_trackdata{nullptr};
- char* opt_trackdirection{nullptr};
- char* opt_units{nullptr};
- char* opt_labels{nullptr};
- char* opt_max_position_points{nullptr};
- char* opt_rotate_colors{nullptr};
- char* opt_precision{nullptr};
+ OptionCString opt_deficon;
+ OptionBool opt_export_lines;
+ OptionBool opt_export_points;
+ OptionBool opt_export_track;
+ OptionCString opt_line_width;
+ OptionCString opt_line_color;
+ OptionBool opt_floating;
+ OptionBool opt_extrude;
+ OptionBool opt_trackdata;
+ OptionBool opt_trackdirection;
+ OptionCString opt_units;
+ OptionBool opt_labels;
+ OptionCString opt_max_position_points;
+ OptionCString opt_rotate_colors;
+ OptionCString opt_precision;
bool export_lines{};
bool export_points{};
waypt_out_count = 0;
writing_version = xstrtoi(opt_wversion, nullptr, 10);
if ((writing_version < 2) || (writing_version > 4)) {
- fatal(MYNAME " wversion value %s is not supported !!\n", opt_wversion);
+ fatal(MYNAME " wversion value %s is not supported !!\n", qPrintable(opt_wversion.get()));
}
utf16le_codec = QTextCodec::codecForName("UTF-16LE");
waypt_table = new QList<const Waypoint*>;
double longitude = lon_mm_to_deg(gbfgetint32(file_in));
int icon_number = gbfgetint32(file_in);
- if (opt_ignoreicons == nullptr) { /* Option not specified if NULL */
+ if (!opt_ignoreicons) {
auto* wpt_tmp = new Waypoint;
/* position coord lat & long */
buf = QString("GPSBabel generated USR data file");
} else {
if (len > MAXUSRSTRINGSIZE) {
- opt_title[MAXUSRSTRINGSIZE] = '\000'; // truncate it before copy
+ QString title = opt_title.get();
+ title.truncate(MAXUSRSTRINGSIZE);
+ opt_title.set(title); // truncate it before copy
}
buf = opt_title;
}
buf = QString("Waypoints, routes, and trails");
} else {
if (len > MAXUSRSTRINGSIZE) {
- opt_content_descr[MAXUSRSTRINGSIZE] = '\000'; // truncate it before copy
+ QString content_descr = opt_content_descr.get();
+ content_descr.truncate(MAXUSRSTRINGSIZE);
+ opt_content_descr.set(content_descr); // truncate it before copy
}
buf = opt_content_descr;
}
#include "defs.h"
#include "format.h"
-#include "formspec.h" // for FsChainFind, FsChainAdd, kFsLowranceusr4, FormatSpecificData
-#include "gbfile.h" // for gbfgetint32, gbfputint32, gbfputint16, gbfgetc, gbfgetint16, gbfwrite, gbfputc, gbfeof, gbfgetflt, gbfclose, gbfgetdbl, gbfopen_le, gbfputdbl, gbfputs, gbfile, gbfputflt, gbfread, gbfseek
-#include "mkshort.h" // for MakeShort
-#include "src/core/datetime.h" // for DateTime
+#include "formspec.h" // for FsChainFind, FsChainAdd, kFsLowranceusr4, FormatSpecificData
+#include "gbfile.h" // for gbfgetint32, gbfputint32, gbfputint16, gbfgetc, gbfgetint16, gbfwrite, gbfputc, gbfeof, gbfgetflt, gbfclose, gbfgetdbl, gbfopen_le, gbfputdbl, gbfputs, gbfile, gbfputflt, gbfread, gbfseek
+#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionBool, OptionCString
+#include "src/core/datetime.h" // for DateTime
class LowranceusrFormat : public Format
int route_uid{};
int trail_uid{};
- char* opt_ignoreicons{};
- char* opt_writeasicons{};
- char* opt_seg_break{};
- char* opt_wversion{};
- char* opt_title{};
- char* opt_content_descr{};
- char* opt_serialnum{};
+ OptionBool opt_ignoreicons;
+ OptionBool opt_writeasicons;
+ OptionBool opt_seg_break;
+ OptionCString opt_wversion;
+ OptionCString opt_title;
+ OptionCString opt_content_descr;
+ OptionCString opt_serialnum;
int opt_serialnum_i{};
QList<const Waypoint*>* waypt_table{nullptr};
int trail_point_count{};
bool merge_new_track{false};
short num_section_points{};
- char* merge{};
+ OptionBool merge;
int reading_version{};
int rstream_version{};
int writing_version{};
char* fusage = nullptr;
- if (*OPT_erase_only != '0') {
+ if (OPT_erase_only) {
mtk_erase();
return;
}
}
// Fixme - Order or. Enable - parse - erase ??
- if (log_enabled || *OPT_log_enable=='1') {
+ if (log_enabled || OPT_log_enable) {
i = do_cmd(CMD_LOG_ENABLE, "PMTK001,182,4,3", nullptr, 2);
dbg(3, " ---- LOG ENABLE ----%s\n", i==0?"Success":"Fail");
} else {
file_deinit();
/* fixme -- we're assuming all went well - erase flash.... */
- if (*OPT_erase != '0') {
+ if (OPT_erase) {
mtk_erase();
}
/********************** MTK Logger -- CSV output *************************/
-void MtkLoggerBase::mtk_csv_init(char* csv_fname, unsigned long bitmask)
+void MtkLoggerBase::mtk_csv_init(const char* csv_fname, unsigned long bitmask)
{
FILE* cf;
mtk_info.logLen = mtk_log_len(mtk_info.bitmask);
dbg(3, "Log item size %d bytes\n", mtk_info.logLen);
if (csv_file && *csv_file) {
- mtk_csv_init(csv_file, mtk_info.bitmask);
+ mtk_csv_init(static_cast<const char*>(csv_file), mtk_info.bitmask);
}
while (pos < fsize && (bLen = fread(&buf[j], 1, sizeof(buf)-j, fl)) > 0) {
#include "defs.h"
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
+#include "option.h" // for OptionBool, OptionCString
class MtkLoggerBase
void* fd{}; /* serial fd */
FILE* fl{}; /* bin.file fd */
char* port{}; /* serial port name */
- char* OPT_erase{}; /* erase ? command option */
- char* OPT_erase_only{}; /* erase_only ? command option */
- char* OPT_log_enable{}; /* enable ? command option */
- char* csv_file{}; /* csv ? command option */
- char* OPT_block_size_kb{}; /* block_size_kb ? command option */
+ OptionBool OPT_erase; /* erase ? command option */
+ OptionBool OPT_erase_only; /* erase_only ? command option */
+ OptionBool OPT_log_enable; /* enable ? command option */
+ OptionCString csv_file; /* csv ? command option */
+ OptionCString OPT_block_size_kb; /* block_size_kb ? command option */
MTK_DEVICE_TYPE mtk_device = MTK_LOGGER;
mtk_loginfo mtk_info{};
int mtk_erase();
void mtk_read();
int add_trackpoint(int idx, long unsigned int bmask, data_item* itm);
- void mtk_csv_init(char* csv_fname, long unsigned int bitmask);
+ void mtk_csv_init(const char* csv_fname, long unsigned int bitmask);
void mtk_csv_deinit();
static int csv_line(gbfile* csvFile, int idx, long unsigned int bmask, data_item* itm);
int mtk_parse(unsigned char* data, int dataLen, unsigned int bmask);
*/
#define MYNAME "nmea"
-#define CHECK_BOOL(a) if ((a) && (*(a) == '0')) (a) = NULL
/*
* Slightly different than the Magellan checksum fn.
datum = kDatumWGS84;
had_checksum = false;
- CHECK_BOOL(opt_gprmc);
- CHECK_BOOL(opt_gpgga);
- CHECK_BOOL(opt_gpvtg);
- CHECK_BOOL(opt_gpgsa);
- CHECK_BOOL(opt_gisteq);
-
pcmpt_head.clear();
if (getposnarg) {
void
NmeaFormat::wr_init(const QString& fname)
{
- CHECK_BOOL(opt_gprmc);
- CHECK_BOOL(opt_gpgga);
- CHECK_BOOL(opt_gpvtg);
- CHECK_BOOL(opt_gpgsa);
- CHECK_BOOL(opt_gisteq);
-
- append_output = strtod(opt_append, nullptr);
-
- file_out = gbfopen(fname, append_output ? "a+" : "w+", MYNAME);
+ file_out = gbfopen(fname, opt_append ? "a+" : "w+", MYNAME);
sleepms = -1;
if (opt_sleep) {
mkshort_handle->set_length(xstrtoi(snlenopt, nullptr, 10));
if (opt_gisteq) {
- opt_gpgga = nullptr;
- opt_gpvtg = nullptr;
- opt_gpgsa = nullptr;
+ opt_gpgga.reset();
+ opt_gpvtg.reset();
+ opt_gpgsa.reset();
}
}
* as serial units will often spit a remembered position up and
* that is more comfortable than nothing at all...
*/
- CHECK_BOOL(opt_ignorefix);
if ((fix <= 0) && (read_mode != rm_serial || (latdeg == 0.0 && lngdeg == 0.0)) && (!opt_ignorefix)) {
return;
}
}
if (optdate) {
- opt_tm = QDate::fromString(optdate, u"yyyyMMdd");
+ opt_tm = QDate::fromString(optdate.get(), u"yyyyMMdd");
if (!opt_tm.isValid()) {
- fatal(MYNAME ": Invalid date \"%s\"!\n", optdate);
+ fatal(MYNAME ": Invalid date \"%s\"!\n", qPrintable(optdate.get()));
}
}
if (opt_baud) {
if (!gbser_set_speed(gbser_handle, xstrtoi(opt_baud, nullptr, 10))) {
- fatal(MYNAME ": Unable to set baud rate %s\n", opt_baud);
+ fatal(MYNAME ": Unable to set baud rate %s\n", qPrintable(opt_baud.get()));
}
}
posn_fname = fname;
#ifndef NMEA_H_INCLUDED_
#define NMEA_H_INCLUDED_
-#include <QByteArray> // for QByteArray
-#include <QDate> // for QDate
-#include <QDateTime> // for QDateTime
-#include <QList> // for QList
-#include <QString> // for QString
-#include <QTime> // for QTime
-#include <QVector> // for QVector
+#include <QByteArray> // for QByteArray
+#include <QDate> // for QDate
+#include <QDateTime> // for QDateTime
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QTime> // for QTime
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h" // for Format
-#include "gbfile.h" // for gbfile
-#include "mkshort.h" // for MakeShort
+#include "format.h" // for Format
+#include "gbfile.h" // for gbfile
+#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionBool, OptionCString
class NmeaFormat : public Format
int without_date{}; /* number of created trackpoints without a valid date */
QDate opt_tm; /* converted "date" parameter */
- char* opt_gprmc{};
- char* opt_gpgga{};
- char* opt_gpvtg{};
- char* opt_gpgsa{};
- char* snlenopt{};
- char* optdate{};
- char* getposnarg{};
- char* opt_sleep{};
- char* opt_baud{};
- char* opt_append{};
- char* opt_gisteq{};
- char* opt_ignorefix{};
+ OptionBool opt_gprmc;
+ OptionBool opt_gpgga;
+ OptionBool opt_gpvtg;
+ OptionBool opt_gpgsa;
+ OptionCString snlenopt;
+ OptionCString optdate;
+ OptionBool getposnarg;
+ OptionCString opt_sleep;
+ OptionCString opt_baud;
+ OptionBool opt_append;
+ OptionBool opt_gisteq;
+ OptionBool opt_ignorefix;
long sleepms{};
int getposn{};
- int append_output{};
bool amod_waypoint{};
QDateTime last_write_time;
void NukeDataFilter::process()
{
- if (*nukewpts != '0') {
+ if (nukewpts) {
waypt_flush_all();
}
- if (*nuketrks != '0') {
+ if (nuketrks) {
route_flush_all_tracks();
}
- if (*nukertes != '0') {
+ if (nukertes) {
route_flush_all_routes();
}
}
#ifndef NUKEDATA_H_INCLUDED_
#define NUKEDATA_H_INCLUDED_
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, arglist_t, ARG_TERMI...
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool
#if FILTERS_ENABLED
void process() override;
private:
- char* nukewpts{};
- char* nuketrks{};
- char* nukertes{};
+ OptionBool nukewpts;
+ OptionBool nuketrks;
+ OptionBool nukertes;
QVector<arglist_t> args = {
{
--- /dev/null
+/*
+ Copyright (C) 2024 Robert Lipe, robertlipe+source@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ */
+#ifndef OPTION_H_INCLUDED_
+#define OPTION_H_INCLUDED_
+
+#include <QByteArray> // for QByteArray
+#include <QString> // for QString, operator!=
+
+class Option /* Abstract Class */
+{
+public:
+ /* Types */
+ enum option_t {
+ type_cstring,
+ type_boolean,
+ };
+
+ /* Special Member Functions */
+ Option() = default;
+ // Provide virtual public destructor to avoid undefined behavior when
+ // an object of derived class type is deleted through a pointer to
+ // its base class type.
+ // https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP52-CPP.+Do+not+delete+a+polymorphic+object+without+a+virtual+destructor
+ virtual ~Option() = default;
+ // And that requires us to explicitly default or delete the move and copy operations.
+ // To prevent slicing we delete them.
+ // https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all.
+ Option(const Option&) = delete;
+ Option& operator=(const Option&) = delete;
+ Option(Option&&) = delete;
+ Option& operator=(Option&&) = delete;
+
+ /* Member Functions */
+ [[nodiscard]] virtual option_t type() const = 0;
+ [[nodiscard]] virtual bool has_value() const = 0;
+ virtual void reset() = 0;
+ [[nodiscard]] virtual bool isEmpty() const = 0;
+ [[nodiscard]] virtual const QString& get() const = 0;
+ virtual void set(const QString& s) = 0;
+
+ /* Data Members */
+ // I.25: Prefer empty abstract classes as interfaces to class hierarchies
+ // https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i25-prefer-empty-abstract-classes-as-interfaces-to-class-hierarchies
+};
+
+class OptionCString : public Option
+{
+public:
+ /* Special Member Functions */
+ OptionCString() = default;
+
+ /* Traditionally a nullptr value indicated the option was not supplied.
+ * This was convenient because a char* can be implicitly converted to bool,
+ * although now we also have the equivalent member function has_value().
+ * Because QByteArray::constData() != nullptr for a null QByteArray we
+ * have to handle that case manually.
+ */
+ explicit(false) operator const char* () const
+ {
+ return value_.isNull()? nullptr : valueb_.constData();
+ }
+
+ [[nodiscard]] option_t type() const override
+ {
+ return type_cstring;
+ }
+
+ [[nodiscard]] bool has_value() const override
+ {
+ return !value_.isNull();
+ }
+
+ void reset() override
+ {
+ value_ = QString();
+ valueb_ = QByteArray();
+ }
+
+ [[nodiscard]] bool isEmpty() const override
+ {
+ return value_.isEmpty();
+ }
+
+ [[nodiscard]] const QString& get() const override
+ {
+ return value_;
+ }
+
+ [[nodiscard]] const QByteArray& getba() const
+ {
+ return valueb_;
+ }
+
+ void set(const QString& s) override
+ {
+ value_ = s;
+ valueb_ = s.toUtf8();
+ }
+
+private:
+ QString value_;
+ QByteArray valueb_;
+};
+
+class OptionBool : public Option
+{
+public:
+ /* Special Member Functions */
+ OptionBool() = default;
+
+ /* Traditionally unsupplied bool options without default are considered to be false. */
+ explicit(false) operator bool() const
+ {
+ return (!value_.isNull() && (value_ != '0'));
+ }
+
+ [[nodiscard]] option_t type() const override
+ {
+ return type_boolean;
+ }
+
+ /* Note that has_value can be used to distinguish an option that wasn't supplied
+ * from one that was supplied and is considered false by Vecs::assign_option.
+ */
+ [[nodiscard]] bool has_value() const override
+ {
+ return !value_.isNull();
+ }
+
+ void reset() override
+ {
+ value_ = QString();
+ }
+
+ [[nodiscard]] bool isEmpty() const override
+ {
+ return value_.isEmpty();
+ }
+
+ [[nodiscard]] const QString& get() const override
+ {
+ return value_;
+ }
+
+ void set(const QString& s) override
+ {
+ value_ = s;
+ }
+
+private:
+ QString value_;
+};
+#endif // OPTION_H_INCLUDED_
break;
}
- if (QString creator = created_by; !creator.isEmpty()) {
+ if (QString creator = created_by.get(); !creator.isEmpty()) {
if (!gpsbabel_testmode()) {
if (creator == "GPSBabel") {
creator += '-';
osm_disp_feature(waypoint);
}
- osm_write_opt_tag(opt_tagnd);
+ osm_write_opt_tag(opt_tagnd.get());
fout->writeEndElement(); // node
}
return;
}
- if (QString creator = created_by; !creator.isEmpty()) {
+ if (QString creator = created_by.get(); !creator.isEmpty()) {
if (!gpsbabel_testmode()) {
if (creator == "GPSBabel") {
creator += '-';
osm_write_tag("name", route->rte_name);
osm_write_tag("note", route->rte_desc);
- osm_write_opt_tag(opt_tag);
+ osm_write_opt_tag(opt_tag.get());
fout->writeEndElement(); // way
}
#include "defs.h"
#include "format.h" // for Format
+#include "option.h" // for OptionCString
#include "src/core/file.h" // for File
#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter
#include "xmlgeneric.h" // for xg_functor_map_entry, cb_start, cb_end
/* Data Members */
- char* opt_tag{};
- char* opt_tagnd{};
- char* created_by{};
+ OptionCString opt_tag;
+ OptionCString opt_tagnd;
+ OptionCString created_by;
QVector<arglist_t> osm_args = {
{ "tag", &opt_tag, "Write additional way tag key/value pairs", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr},
alt_scale = FEET_TO_METERS(1.0);
break;
default:
- fatal(MYNAME ": Unknown value (%s) for option 'altunit'!\n", altunit_opt);
+ fatal(MYNAME ": Unknown value (%s) for option 'altunit'!\n", qPrintable(altunit_opt.get()));
}
if (direction != 0) {
alt_scale = 1 / alt_scale;
prox_scale = 1000.0;
break;
default:
- fatal(MYNAME ": Unknown value (%s) for option 'proxunit'!\n", proxunit_opt);
+ fatal(MYNAME ": Unknown value (%s) for option 'proxunit'!\n", qPrintable(proxunit_opt.get()));
}
if (direction != 0) {
prox_scale = 1 / prox_scale;
mkshort_handle->set_length(xstrtoi(snlenopt, nullptr, 10));
- if (snwhiteopt) {
- mkshort_handle->set_whitespace_ok(xstrtoi(snwhiteopt, nullptr, 10));
+ if (snwhiteopt.has_value()) {
+ mkshort_handle->set_whitespace_ok(snwhiteopt);
}
- if (snupperopt) {
- mkshort_handle->set_mustupper(xstrtoi(snupperopt, nullptr, 10));
+ if (snupperopt.has_value()) {
+ mkshort_handle->set_mustupper(snupperopt);
}
- if (snuniqueopt) {
- mkshort_handle->set_mustuniq(xstrtoi(snuniqueopt, nullptr, 10));
+ if (snuniqueopt.has_value()) {
+ mkshort_handle->set_mustuniq(snuniqueopt);
}
mkshort_handle->set_badchars("\",");
#ifndef OZI_H_INCLUDED_
#define OZI_H_INCLUDED_
+#include <QList> // for QList
#include <QIODevice> // for QIODeviceBase, QIODeviceBase::OpenModeFlag
#include <QString> // for QString
#include <QVector> // for QVector
#include "format.h" // for Format
#include "formspec.h" // for FormatSpecificData, kFsOzi
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionCString, OptionBool
#include "src/core/textstream.h" // for TextStream
int route_wpt_count{};
int new_track{};
- char* snlenopt = nullptr;
- char* snwhiteopt = nullptr;
- char* snupperopt = nullptr;
- char* snuniqueopt = nullptr;
- char* wptfgcolor = nullptr;
- char* wptbgcolor = nullptr;
- char* pack_opt = nullptr;
+ OptionCString snlenopt;
+ OptionBool snwhiteopt;
+ OptionBool snupperopt;
+ OptionBool snuniqueopt;
+ OptionCString wptfgcolor;
+ OptionCString wptbgcolor;
+ OptionBool pack_opt;
int datum{};
- char* proximityarg = nullptr;
+ OptionCString proximityarg;
double proximity{};
- char* altunit_opt{};
- char* proxunit_opt{};
+ OptionCString altunit_opt;
+ OptionCString proxunit_opt;
char altunit{};
char proxunit{};
double alt_scale{};
double prox_scale{};
- char* opt_codec{};
+ OptionCString opt_codec;
QVector<arglist_t> ozi_args = {
{
QString line;
gpsbabel::TextStream stream;
- stream.open(polyfileopt, QIODevice::ReadOnly, MYNAME);
+ stream.open(polyfileopt.get(), QIODevice::ReadOnly, MYNAME);
double olat = BADVAL;
double olon = BADVAL;
if (ed->override) {
ed->state = INSIDE;
}
- if (((ed->state & INSIDE) == OUTSIDE) == (exclopt == nullptr)) {
+ if (((ed->state & INSIDE) == OUTSIDE) == !exclopt) {
wp->wpt_flags.marked_for_deletion = 1;
}
delete ed;
#ifndef POLYGON_H_INCLUDED_
#define POLYGON_H_INCLUDED_
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h" // for ARG_NOMINMAX, arglist_t, ARGTYPE_BOOL, ARGTYPE_FILE
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool, OptionCString
#if FILTERS_ENABLED
/* Data Members */
- char* polyfileopt = nullptr;
- char* exclopt = nullptr;
+ OptionCString polyfileopt;
+ OptionBool exclopt;
QVector<arglist_t> args = {
{
#include <QtGlobal> // for qRound64, qint64
#include "defs.h"
+#include "grtcirc.h" // for gcdist, radtometers
#include "src/core/datetime.h" // for DateTime
#if FILTERS_ENABLED
}
}
- if (something_deleted && (purge_duplicates != nullptr)) {
+ if (something_deleted && purge_duplicates) {
qlist.at(i).wpt->wpt_flags.marked_for_deletion = 1;
}
}
#ifndef POSITION_H_INCLUDED_
#define POSITION_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include <QtGlobal> // for qint64
#include "defs.h" // for arglist_t, route_head (ptr only), ARG_NOMINMAX, ARGTYPE_FLOAT, ARGTYPE_REQUIRED, ARGTYPE_BOOL, Waypoint, WaypointList (ptr only)
#include "filter.h" // for Filter
-#include "grtcirc.h" // for RAD, gcdist, radtometers
+#include "option.h" // for OptionCString, OptionBool
#if FILTERS_ENABLED
double pos_dist{};
qint64 max_diff_time{};
- char* distopt = nullptr;
- char* timeopt = nullptr;
- char* purge_duplicates = nullptr;
+ OptionCString distopt;
+ OptionCString timeopt;
+ OptionBool purge_duplicates;
bool check_time{};
QVector<arglist_t> args = {
#include <QtGlobal> // QAddConst<>::Type, foreach
#include "defs.h" // for Waypoint, del_marked_wpts, route_add_head, route_add_wpt, waypt_add, waypt_sort, waypt_swap, xstrtoi, route_head, WaypointList, kMilesPerKilometer
+#include "grtcirc.h" // for gcdist, radtomiles
#if FILTERS_ENABLED
double dist = radtomiles(gcdist(waypointp->position(),
home_pos->position()));
- if ((dist >= pos_dist) == (exclopt == nullptr)) {
+ if ((dist >= pos_dist) == !exclopt) {
waypointp->wpt_flags.marked_for_deletion = 1;
} else {
auto* ed = new extra_data;
}
del_marked_wpts();
- if (nosort == nullptr) {
+ if (!nosort) {
auto dist_comp_lambda = [](const Waypoint* a, const Waypoint* b)->bool {
const auto* aed = static_cast<const extra_data*>(a->extra_data);
const auto* bed = static_cast<const extra_data*>(b->extra_data);
#ifndef RADIUS_H_INCLUDED_
#define RADIUS_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h" // for arglist_t, ARG_NOMINMAX, ARGTYPE_FLOAT, ARGTYPE_REQUIRED, ARGTYPE_BOOL, ARGTYPE_INT, ARGTYPE_STRING, Waypoint
#include "filter.h" // for Filter
-#include "grtcirc.h" // for RAD, gcdist, radtomiles
+#include "option.h" // for OptionCString, OptionBool
#if FILTERS_ENABLED
/* Data Members */
double pos_dist{};
- char* distopt = nullptr;
- char* latopt = nullptr;
- char* lonopt = nullptr;
- char* exclopt = nullptr;
- char* nosort = nullptr;
- char* maxctarg = nullptr;
- char* routename = nullptr;
+ OptionCString distopt;
+ OptionCString latopt;
+ OptionCString lonopt;
+ OptionBool exclopt;
+ OptionBool nosort;
+ OptionCString maxctarg;
+ OptionCString routename;
int maxct{};
Waypoint* home_pos{};
#ifndef RANDOM_H_INCLUDED_
#define RANDOM_H_INCLUDED_
-#include <random> // for mt19937
+#include <random> // for mt19937
-#include <QDateTime> // for QDateTime
-#include <QString> // for QString
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QDateTime> // for QDateTime
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h"
+#include "format.h" // for Format
+#include "option.h" // for OptionCString, OptionBool
class RandomFormat : public Format
/* Data Members */
- char* opt_points{nullptr};
- char* opt_seed{nullptr};
- char* opt_nodelay{nullptr};
+ OptionCString opt_points;
+ OptionCString opt_seed;
+ OptionBool opt_nodelay;
QVector<arglist_t> random_args = {
{
#include <tuple> // for tuple
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h" // for arglist_t, ARGTYPE_INT, Waypoint, route_head
#include "filter.h" // for Filter
+#include "option.h" // for OptionCString
#include "src/core/nvector.h" // for NVector
int decimate_count{0};
int interpolate_count{0};
- char* decimateopt{nullptr};
- char* interpolateopt{nullptr};
- char* averageopt{nullptr};
+ OptionCString decimateopt;
+ OptionCString interpolateopt;
+ OptionCString averageopt;
QVector<arglist_t> args = {
{
#ifndef SHAPE_H_INCLUDED_
#define SHAPE_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h" // for arglist_t, ARGTYPE_STRING, Waypoint, route_head, FF_CAP_RW_ALL, ff_cap, ff_type, ff_type_file
#include "format.h" // for Format
+#include "option.h" // for OptionCString
#if SHAPELIB_ENABLED
#if HAVE_LIBSHAPE
# include <shapefil.h>
QString ofname;
int nameFieldIdx{}; // the field index of the field with fieldName "name" in the output DBF.
- char* opt_name = nullptr;
- char* opt_url = nullptr;
+ OptionCString opt_name;
+ OptionCString opt_url;
QVector<arglist_t> shp_args = {
{
// m.ad/090930: removed code that tried reducing read_at_once if necessary since doesn't work with xmalloc
if (opt_dump_file) {
- dumpfile = gbfopen(opt_dump_file, "w", MYNAME);
+ dumpfile = gbfopen(opt_dump_file.get(), "w", MYNAME);
}
db(1, MYNAME ": Reading log data from device...\n");
gbfwrite(buffer, SECTOR_SIZE, got_sectors, dumpfile);
}
- if (*opt_no_output == '1') {
+ if (opt_no_output) {
continue; // skip decoding
}
uint8_t MSG_SET_LOCATION[17] = { 0x36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
uint8_t MSG_GET_LOCATION = 0x35;
- db(3, MYNAME ": set_location='%s'\n", opt_set_location);
+ db(3, MYNAME ": set_location='%s'\n", qPrintable(opt_set_location.get()));
sscanf(opt_set_location, "%lf:%lf", &lat, &lng);
le_write_double(&MSG_SET_LOCATION[1], lat);
skytraq_set_baud(dlbaud);
}
- // read device unless no-output=1 and dump-file=0 (i.e. no data needed at all)
- if (*opt_no_output == '0' || opt_dump_file != nullptr) {
+ // read device unless no-output=true and dump-file=0 (i.e. no data needed at all)
+ if (!opt_no_output || opt_dump_file != nullptr) {
skytraq_read_tracks();
}
- if (*opt_erase == '1') {
+ if (opt_erase) {
skytraq_erase();
}
void
MinihomerFormat::rd_init(const QString& fname)
{
- opt_set_location=nullptr; // otherwise it will lead to bus error
+ opt_set_location.reset(); // otherwise it will lead to bus error
skytraq_rd_init(fname); // sets global var serial_handle
mhport=fname;
}
#ifndef SKYTRAQ_H_INCLUDED_
#define SKYTRAQ_H_INCLUDED_
+#include <QList> // for QList
#include <QDateTime> // for QDateTime
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h"
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
+#include "option.h" // for OptionCString, OptionBool
class SkytraqBase
void* serial_handle = nullptr; /* IO file descriptor */
int skytraq_baud = 0; /* detected baud rate */
- char* opt_erase = nullptr; /* erase after read? (0/1) */
- char* opt_initbaud = nullptr; /* baud rate used to init device */
- char* opt_dlbaud = nullptr; /* baud rate used for downloading tracks */
- char* opt_read_at_once = nullptr; /* number of sectors to read at once (Venus6 only) */
- char* opt_first_sector = nullptr; /* first sector to be read from the device (default: 0) */
- char* opt_last_sector = nullptr; /* last sector to be read from the device (default: smart read everything) */
- char* opt_dump_file = nullptr; /* dump raw data to this file (optional) */
- char* opt_no_output = nullptr; /* disable output? (0/1) */
- char* opt_set_location = nullptr; /* set if the "targetlocation" options was used */
- char* opt_configure_logging = nullptr;
- char* opt_gps_utc_offset = nullptr;
- char* opt_gps_week_rollover = nullptr;
+ OptionBool opt_erase; /* erase after read? (0/1) */
+ OptionCString opt_initbaud; /* baud rate used to init device */
+ OptionCString opt_dlbaud; /* baud rate used for downloading tracks */
+ OptionCString opt_read_at_once; /* number of sectors to read at once (Venus6 only) */
+ OptionCString opt_first_sector; /* first sector to be read from the device (default: 0) */
+ OptionCString opt_last_sector; /* last sector to be read from the device (default: smart read everything) */
+ OptionCString opt_dump_file; /* dump raw data to this file (optional) */
+ OptionBool opt_no_output; /* disable output? (0/1) */
+ OptionCString opt_set_location; /* set if the "targetlocation" options was used */
+ OptionCString opt_configure_logging;
+ OptionCString opt_gps_utc_offset;
+ OptionCString opt_gps_week_rollover;
};
class SkytraqFormat : public Format, private SkytraqBase
/* Data Members */
- char* opt_set_poi_home = nullptr; /* set if a "poi" option was used */
- char* opt_set_poi_car = nullptr; /* set if a "poi" option was used */
- char* opt_set_poi_boat = nullptr; /* set if a "poi" option was used */
- char* opt_set_poi_heart = nullptr; /* set if a "poi" option was used */
- char* opt_set_poi_bar = nullptr; /* set if a "poi" option was used */
+ OptionCString opt_set_poi_home; /* set if a "poi" option was used */
+ OptionCString opt_set_poi_car; /* set if a "poi" option was used */
+ OptionCString opt_set_poi_boat; /* set if a "poi" option was used */
+ OptionCString opt_set_poi_heart; /* set if a "poi" option was used */
+ OptionCString opt_set_poi_bar; /* set if a "poi" option was used */
QVector<arglist_t> miniHomer_args = {
{ "baud", &opt_dlbaud, "Baud rate used for download", "115200", ARGTYPE_INT, "0", "115200", nullptr },
#ifndef SMPLROUT_H_INCLUDED_
#define SMPLROUT_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
-#include <QStringView> // for QStringView
#include <QVector> // for QVector
#include "defs.h"
-#include "filter.h" // for Filter
+#include "filter.h" // for Filter
+#include "option.h" // for OptionBool, OptionCString
#if FILTERS_ENABLED
limit_basis_t limit_basis{limit_basis_t::error};
metric_t metric{metric_t::crosstrack};
- char* countopt = nullptr;
- char* erroropt = nullptr;
- char* xteopt = nullptr;
- char* lenopt = nullptr;
- char* relopt = nullptr;
+ OptionCString countopt;
+ OptionCString erroropt;
+ OptionBool xteopt;
+ OptionBool lenopt;
+ OptionBool relopt;
QVector<arglist_t> args = {
{
#ifndef SORT_H_INCLUDED_
#define SORT_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h" // for arglist_t, ARGTYPE_BOOL, ARG_NOMINMAX, Waypoint
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool
#if FILTERS_ENABLED
SortModeRteHd rte_sort_mode{SortModeRteHd::none}; /* How are we sorting these? */
SortModeRteHd trk_sort_mode{SortModeRteHd::none}; /* How are we sorting these? */
- char* opt_sm_gcid{};
- char* opt_sm_shortname{};
- char* opt_sm_description{};
- char* opt_sm_time{};
- char* opt_sm_rtenum{};
- char* opt_sm_rtename{};
- char* opt_sm_rtedesc{};
- char* opt_sm_trknum{};
- char* opt_sm_trkname{};
- char* opt_sm_trkdesc{};
+ OptionBool opt_sm_gcid;
+ OptionBool opt_sm_shortname;
+ OptionBool opt_sm_description;
+ OptionBool opt_sm_time;
+ OptionBool opt_sm_rtenum;
+ OptionBool opt_sm_rtename;
+ OptionBool opt_sm_rtedesc;
+ OptionBool opt_sm_trknum;
+ OptionBool opt_sm_trkname;
+ OptionBool opt_sm_trkdesc;
QVector<arglist_t> args = {
{
#ifndef STACKFILTER_H_INCLUDED_
#define STACKFILTER_H_INCLUDED_
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, ARGTYPE_BEGIN_EXCL
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool, OptionCString
#if FILTERS_ENABLED
void exit() override;
private:
- char* opt_push = nullptr;
- char* opt_copy = nullptr;
- char* opt_pop = nullptr;
- char* opt_append = nullptr;
- char* opt_discard = nullptr;
- char* opt_replace = nullptr;
- char* opt_swap = nullptr;
- char* opt_depth = nullptr;
- char* nowarn = nullptr;
+ OptionBool opt_push;
+ OptionBool opt_copy;
+ OptionBool opt_pop;
+ OptionBool opt_append;
+ OptionBool opt_discard;
+ OptionBool opt_replace;
+ OptionBool opt_swap;
+ OptionCString opt_depth;
+ OptionBool nowarn;
int warnings_enabled = 1;
int swapdepth = 0;
starttime.hour(), starttime.minute(), starttime.second(), starttime.msec(),
endtime.hour(), endtime.minute(), endtime.second(), endtime.msec());
- for (char* c = opt_format; *c != '\0' ; c++) {
+ for (const char* c = static_cast<const char*>(opt_format); *c != '\0' ; c++) {
char fmt;
switch (*c) {
}
gps_datetime = QDateTime();
if ((opt_gpstime != nullptr) && (opt_gpsdate != nullptr)) {
- QDate gps_date = QDate::fromString(opt_gpsdate, u"yyyyMMdd");
+ QDate gps_date = QDate::fromString(opt_gpsdate.get(), u"yyyyMMdd");
if (!gps_date.isValid()) {
fatal(FatalMsg().nospace() << MYNAME ": option gps_date value (" << opt_gpsdate << ") is invalid. Expected yyyymmdd.");
}
- QTime gps_time = QTime::fromString(opt_gpstime, u"HHmmss");
+ QTime gps_time = QTime::fromString(opt_gpstime.get(), u"HHmmss");
if (!gps_time.isValid()) {
- gps_time = QTime::fromString(opt_gpstime, u"HHmmss.z");
+ gps_time = QTime::fromString(opt_gpstime.get(), u"HHmmss.z");
if (!gps_time.isValid()) {
fatal(FatalMsg().nospace() << MYNAME ": option gps_time value (" << opt_gpstime << ") is invalid. Expected hhmmss[.sss]");
}
video_offset_ms = 0;
if (opt_videotime != nullptr) {
- QTime video_time = QTime::fromString(opt_videotime, u"HHmmss");
+ QTime video_time = QTime::fromString(opt_videotime.get(), u"HHmmss");
if (!video_time.isValid()) {
- video_time = QTime::fromString(opt_videotime, u"HHmmss.z");
+ video_time = QTime::fromString(opt_videotime.get(), u"HHmmss.z");
if (!video_time.isValid()) {
fatal(FatalMsg().nospace() << MYNAME ": option video_time value (" << opt_videotime << ") is invalid. Expected hhmmss[.sss].");
}
#ifndef SUBRIP_H_INCLUDED_
#define SUBRIP_H_INCLUDED_
-#include <QDateTime> // for QDateTime, operator<<
-#include <QString> // for QString
-#include <QTime> // for QTime
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QDateTime> // for QDateTime, operator<<
+#include <QString> // for QString
+#include <QTime> // for QTime
+#include <QVector> // for QVector
#include "defs.h"
-#include "format.h" // for Format
-#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfwrite, gbfile
+#include "format.h" // for Format
+#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfwrite, gbfile
+#include "option.h" // for OptionCString
class SubripFormat : public Format
/* Data Members */
- char* opt_videotime{nullptr};
- char* opt_gpstime{nullptr};
- char* opt_gpsdate{nullptr};
- char* opt_format{nullptr};
+ OptionCString opt_videotime;
+ OptionCString opt_gpstime;
+ OptionCString opt_gpsdate;
+ OptionCString opt_format;
QDateTime gps_datetime; // Date time corresponding to video video_offset_ms
QDateTime video_datetime; // Date time corresponding to video time 00:00:00,000.
int video_offset_ms{0};
#ifndef TEXT_H_INCLUDED_
#define TEXT_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h"
#include "format.h" // for Format
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionBool, OptionCString
#include "src/core/textstream.h" // for TextStream
gpsbabel::TextStream* file_out{nullptr};
MakeShort* mkshort_handle{};
- char* suppresssep = nullptr;
- char* txt_encrypt = nullptr;
- char* includelogs = nullptr;
- char* degformat = nullptr;
- char* altunits = nullptr;
- char* split_output = nullptr;
+ OptionBool suppresssep;
+ OptionBool txt_encrypt;
+ OptionBool includelogs;
+ OptionCString degformat;
+ OptionCString altunits;
+ OptionBool split_output;
int waypoint_count{};
QString output_name;
{
tpg_datum_idx = GPS_Lookup_Datum_Index(tpg_datum_opt);
if (tpg_datum_idx < 0) {
- fatal(MYNAME ": Datum '%s' is not recognized.\n", tpg_datum_opt);
+ fatal(MYNAME ": Datum '%s' is not recognized.\n", qPrintable(tpg_datum_opt.get()));
}
}
#ifndef TPG_H_INCLUDED_
#define TPG_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionCString
class TpgFormat : public Format
gbfile* tpg_file_in{};
gbfile* tpg_file_out{};
MakeShort* mkshort_handle{};
- char* tpg_datum_opt{};
+ OptionCString tpg_datum_opt;
int tpg_datum_idx{};
int waypt_out_count{};
int res = 0;
for (const auto& arg : std::as_const(args)) {
- if (*arg.argval != nullptr) {
+ if (arg.argval->has_value()) {
res++;
}
}
if (!opt_fix) {
return fix_unknown;
}
- if (!case_ignore_strcmp(opt_fix, "pps")) {
+ if (!case_ignore_strcmp(opt_fix.get(), "pps")) {
*nsats = 4;
return fix_pps;
}
- if (!case_ignore_strcmp(opt_fix, "dgps")) {
+ if (!case_ignore_strcmp(opt_fix.get(), "dgps")) {
*nsats = 4;
return fix_dgps;
}
- if (!case_ignore_strcmp(opt_fix, "3d")) {
+ if (!case_ignore_strcmp(opt_fix.get(), "3d")) {
*nsats = 4;
return fix_3d;
}
- if (!case_ignore_strcmp(opt_fix, "2d")) {
+ if (!case_ignore_strcmp(opt_fix.get(), "2d")) {
*nsats = 3;
return fix_2d;
}
- if (!case_ignore_strcmp(opt_fix, "none")) {
+ if (!case_ignore_strcmp(opt_fix.get(), "none")) {
*nsats = 0;
return fix_none;
}
}
if (opt_name != nullptr) {
- QRegularExpression regex(QRegularExpression::wildcardToRegularExpression(opt_name),
+ QRegularExpression regex(QRegularExpression::wildcardToRegularExpression(opt_name.get()),
QRegularExpression::CaseInsensitiveOption);
if (!regex.isValid()) {
fatal(FatalMsg() << "track: name option is an invalid expression.");
strftime(buff, sizeof(buff), opt_title, &tm);
track->rte_name = buff;
} else {
- track->rte_name = QStringLiteral("%1-%2").arg(opt_title, datetimestring);
+ track->rte_name = QStringLiteral("%1-%2").arg(opt_title.get(), datetimestring);
}
} else if (!track->rte_name.isEmpty()) {
track->rte_name = QStringLiteral("%1-%2").arg(track->rte_name, datetimestring);
if (opt_interval != 0) {
static const QRegularExpression re(R"(^([+-]?(?:\d+(?:\.\d*)?|\.\d+))([dhms])$)", QRegularExpression::CaseInsensitiveOption);
assert(re.isValid());
- QRegularExpressionMatch match = re.match(opt_split);
+ QRegularExpressionMatch match = re.match(opt_split.get());
if (match.hasMatch()) {
bool ok;
interval = match.captured(1).toDouble(&ok);
printf(MYNAME ": interval %f seconds\n", interval);
}
} else {
- fatal(MYNAME ": invalid timer interval specified \"%s\", must be a positive number, followed by 'd' for days, 'h' for hours, 'm' for minutes or 's' for seconds.\n", opt_split);
+ fatal(MYNAME ": invalid timer interval specified \"%s\", must be a positive number, followed by 'd' for days, 'h' for hours, 'm' for minutes or 's' for seconds.\n", qPrintable(opt_split.get()));
}
}
if (opt_distance != 0) {
static const QRegularExpression re(R"(^([+-]?(?:\d+(?:\.\d*)?|\.\d+))([km])$)", QRegularExpression::CaseInsensitiveOption);
assert(re.isValid());
- QRegularExpressionMatch match = re.match(opt_sdistance);
+ QRegularExpressionMatch match = re.match(opt_sdistance.get());
if (match.hasMatch()) {
bool ok;
distance = match.captured(1).toDouble(&ok);
printf(MYNAME ": distance %f meters\n", distance);
}
} else {
- fatal(MYNAME ": invalid distance specified \"%s\", must be a positive number followed by 'k' for kilometers or 'm' for miles.\n", opt_sdistance);
+ fatal(MYNAME ": invalid distance specified \"%s\", must be a positive number followed by 'k' for kilometers or 'm' for miles.\n", qPrintable(opt_sdistance.get()));
}
}
}
}
- if (opt_seg2trk != nullptr) {
+ if (opt_seg2trk) {
trackfilter_seg2trk();
// track_list may? now be invalid!
if (--opts == 0) {
init();
}
- if (opt_trk2seg != nullptr) {
+ if (opt_trk2seg) {
trackfilter_trk2seg();
if (--opts == 0) {
return;
bool something_done = false;
- if ((opt_pack != nullptr) || (opts == -1)) { /* call our default option */
+ if (opt_pack || (opts == -1)) { /* call our default option */
trackfilter_pack();
something_done = true;
} else if (opt_merge != nullptr) {
#include "defs.h" // for ARG_NOMINMAX, route_head (ptr only), ARG...
#include "filter.h" // for Filter
+#include "option.h" // for OptionCString, OptionBool
#include "src/core/datetime.h" // for DateTime
#if FILTERS_ENABLED || MINIMAL_FILTERS
/* Data Members */
- char* opt_merge = nullptr;
- char* opt_pack = nullptr;
- char* opt_split = nullptr;
- char* opt_sdistance = nullptr;
- char* opt_move = nullptr;
- char* opt_title = nullptr;
- char* opt_start = nullptr;
- char* opt_stop = nullptr;
- char* opt_fix = nullptr;
- char* opt_course = nullptr;
- char* opt_speed = nullptr;
- char* opt_name = nullptr;
- char* opt_seg2trk = nullptr;
- char* opt_trk2seg = nullptr;
- char* opt_segment = nullptr;
- char* opt_faketime = nullptr;
- char* opt_discard = nullptr;
- char* opt_minpoints = nullptr;
+ OptionCString opt_merge;
+ OptionBool opt_pack;
+ OptionCString opt_split;
+ OptionCString opt_sdistance;
+ OptionCString opt_move;
+ OptionCString opt_title;
+ OptionCString opt_start;
+ OptionCString opt_stop;
+ OptionCString opt_fix;
+ OptionBool opt_course;
+ OptionBool opt_speed;
+ OptionCString opt_name;
+ OptionBool opt_seg2trk;
+ OptionBool opt_trk2seg;
+ OptionBool opt_segment;
+ OptionCString opt_faketime;
+ OptionBool opt_discard;
+ OptionCString opt_minpoints;
int minimum_points{0};
QVector<arglist_t> args = {
void TransformFilter::process()
{
- timeless = opt_timeless && (*opt_timeless == '1');
+ timeless = opt_timeless;
- bool delete_after = opt_delete && (*opt_delete == '1');
+ bool delete_after = opt_delete;
- use_src_name = opt_rpt_name && (*opt_rpt_name == '1');
+ use_src_name = opt_rpt_name;
name_digits = 3;
if (rpt_name_digits && *rpt_name_digits) {
}
break;
default:
- fatal(MYNAME ": Invalid option value (%s)!\n", opt_waypts);
+ fatal(MYNAME ": Invalid option value (%s)!\n", qPrintable(opt_waypts.get()));
}
}
if (opt_routes != nullptr) {
}
break;
default:
- fatal(MYNAME ": Invalid option value (%s)!\n", opt_routes);
+ fatal(MYNAME ": Invalid option value (%s)!\n", qPrintable(opt_routes.get()));
}
}
if (opt_tracks != nullptr) {
}
break;
default:
- fatal(MYNAME ": Invalid option value (%s)!\n", opt_tracks);
+ fatal(MYNAME ": Invalid option value (%s)!\n", qPrintable(opt_tracks.get()));
}
}
}
#ifndef TRANSFORM_H_INCLUDED_
#define TRANSFORM_H_INCLUDED_
-#include <QString> // for QString
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
-#include "defs.h" // for route_head (ptr only), ARG_NOMINMAX, ARGTY...
-#include "filter.h" // for Filter
+#include "defs.h" // for route_head (ptr only), ARG_NOMINMAX, ARGTY...
+#include "filter.h" // for Filter
+#include "option.h" // for OptionCString, OptionBool
#if FILTERS_ENABLED
route_head* current_trk{};
route_head* current_rte{};
- char* opt_routes{}, *opt_tracks{}, *opt_waypts{}, *opt_delete{}, *rpt_name_digits{}, *opt_rpt_name{};
- char* opt_timeless{};
+ OptionCString opt_routes;
+ OptionCString opt_tracks;
+ OptionCString opt_waypts;
+ OptionBool opt_delete;
+ OptionCString rpt_name_digits;
+ OptionBool opt_rpt_name;
+ OptionBool opt_timeless;
bool timeless{};
bool use_src_name{};
QString current_namepart;
#include <QDate> // for QDate
#include <QDateTime> // for QDateTime
+#include <QList> // for QList
#include <QString> // for QString
#include <QTime> // for QTime
#include <QVector> // for QVector
#include "defs.h"
#include "format.h" // for Format
#include "geocache.h" // for Geocache, Geocache::status_t
+#include "option.h" // for OptionCString, OptionBool
#include "src/core/textstream.h" // for TextStream
std::bitset<fld_terminator> unicsv_outp_flags;
grid_type unicsv_grid_idx{grid_unknown};
int unicsv_datum_idx{};
- char* opt_datum{nullptr};
- char* opt_grid{nullptr};
- char* opt_utc{nullptr};
- char* opt_filename{nullptr};
- char* opt_format{nullptr};
- char* opt_prec{nullptr};
- char* opt_fields{nullptr};
- char* opt_codec{nullptr};
+ OptionCString opt_datum;
+ OptionCString opt_grid;
+ OptionCString opt_utc;
+ OptionBool opt_filename;
+ OptionBool opt_format;
+ OptionCString opt_prec;
+ OptionCString opt_fields;
+ OptionCString opt_codec;
int unicsv_waypt_ct{};
char unicsv_detect{};
int llprec{};
RteHdFunctor<ValidateFilter> validate_head_f(this, &ValidateFilter::validate_head);
RteHdFunctor<ValidateFilter> validate_head_trl_f(this, &ValidateFilter::validate_head_trl);
- debug = *opt_debug == '1';
- checkempty = *opt_checkempty == '1';
+ debug = opt_debug;
+ checkempty = opt_checkempty;
point_ct = 0;
if (debug) {
#ifndef VALIDATE_H_INCLUDED_
#define VALIDATE_H_INCLUDED_
-#include <QVector> // for QVector
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QVector> // for QVector
#include "defs.h" // for route_head (ptr only), ARGTYPE_BOOL, ARG_NOMINMAX
#include "filter.h" // for Filter
+#include "option.h" // for OptionBool
#if FILTERS_ENABLED
void process() override;
private:
- char* opt_debug{};
+ OptionBool opt_debug;
bool debug{};
- char* opt_checkempty{};
+ OptionBool opt_checkempty;
bool checkempty{};
int point_ct{};
int total_point_ct{};
#ifndef VCF_H_INCLUDED_
#define VCF_H_INCLUDED_
+#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
#include "geocache.h" // for Geocache
+#include "option.h" // for OptionBool
class VcfFormat : public Format
gbfile* file_out{};
- char* vcf_encrypt = nullptr;
+ OptionBool vcf_encrypt;
QVector<arglist_t> vcf_args = {
{
#include <type_traits> // for is_base_of
#include <utility> // for as_const
-#include "defs.h" // for arglist_t, ff_vecs_t, ff_cap, fatal, CSTR, ARGTYPE_TYPEMASK, case_ignore_strcmp, global_options, global_opts, warning, xfree, ARGTYPE_BOOL, ff_cap_read, ff_cap_write, ARGTYPE_HIDDEN, ff_type_internal, xstrdup, ARGTYPE_INT, ARGTYPE_REQUIRED, ARGTYPE_FLOAT
+#include "defs.h" // for arglist_t, CSTR, fatal, ff_cap, ARGTYPE_TYPEMASK, ff_type, ARGTYPE_BOOL, case_ignore_strcmp, gpsdata_type, warning, ff_cap_array, global_options, global_opts, ARGTYPE_FLOAT, ARGTYPE_HIDDEN, ARGTYPE_INT, ARGTYPE_REQUIRED
#include "dg-100.h" // for Dg100FileFormat, Dg100SerialFormat, Dg200FileFormat, Dg200SerialFormat
#include "exif.h" // for ExifFormat
#include "format.h" // for Format
#include "lowranceusr.h" // for LowranceusrFormat
#include "mtk_logger.h" // for MtkFormat, MtkM241Format, MtkFileFormat, MtkM241FileFormat
#include "nmea.h" // for NmeaFormat
+#include "option.h" // for Option, OptionBool
#include "osm.h" // for OsmFormat
#include "ozi.h" // for OziFormat
#include "qstarz_bl_1000.h" // for QstarzBL1000Format
if (args && !args->isEmpty()) {
assert(args->isDetached());
for (auto& arg : *args) {
- arg.argvalptr = nullptr;
- if (arg.argval) {
- *arg.argval = nullptr;
+ if (arg.argval != nullptr) {
+ arg.argval->reset();
}
}
}
if (args && !args->isEmpty()) {
assert(args->isDetached());
for (auto& arg : *args) {
- if (arg.argvalptr) {
- xfree(arg.argvalptr);
- *arg.argval = arg.argvalptr = nullptr;
+ if (arg.argval != nullptr) {
+ arg.argval->reset();
}
}
}
style_list.squeeze();
}
-void Vecs::assign_option(const QString& module, arglist_t* arg, const QString& val)
+void Vecs::assign_option(const QString& module, arglist_t& arg, const QString& val)
{
- if (arg->argval == nullptr) {
- fatal("%s: No local variable defined for option \"%s\"!\n", qPrintable(module), qPrintable(arg->argstring));
+ if (arg.argval == nullptr) {
+ fatal("%s: No local variable defined for option \"%s\"!\n", qPrintable(module), qPrintable(arg.argstring));
}
- if (arg->argvalptr != nullptr) {
- xfree(arg->argvalptr);
- arg->argvalptr = nullptr;
- }
- if (arg->argval) {
- *arg->argval = nullptr;
- }
+ arg.argval->reset();
if (val.isNull()) {
return;
QString rval(val);
- switch (arg->argtype & ARGTYPE_TYPEMASK) {
+ switch (arg.argtype & ARGTYPE_TYPEMASK) {
case ARGTYPE_INT:
if (val.isEmpty()) {
rval = '0';
} else {
if (!is_integer(val)) {
- fatal("%s: Invalid parameter value \"%s\" for option %s!\n", qPrintable(module), qPrintable(val), qPrintable(arg->argstring));
+ fatal("%s: Invalid parameter value \"%s\" for option %s!\n", qPrintable(module), qPrintable(val), qPrintable(arg.argstring));
}
}
break;
rval = '0';
} else {
if (!is_float(val)) {
- fatal("%s: Invalid parameter value \"%s\" for option %s!\n", qPrintable(module), qPrintable(val), qPrintable(arg->argstring));
+ fatal("%s: Invalid parameter value \"%s\" for option %s!\n", qPrintable(module), qPrintable(val), qPrintable(arg.argstring));
}
}
break;
rval = '1';
}
} else {
- warning("%s :Invalid logical value \"%s\" for option %s!\n", qPrintable(module), qPrintable(val), qPrintable(arg->argstring));
+ warning("%s :Invalid logical value \"%s\" for option %s!\n", qPrintable(module), qPrintable(val), qPrintable(arg.argstring));
rval = '0';
}
}
break;
}
- /* for bool options without default: don't set argval if "FALSE" */
-
- if (((arg->argtype & ARGTYPE_TYPEMASK) == ARGTYPE_BOOL) &&
- rval.startsWith('0') && (arg->defaultvalue == nullptr)) {
- return;
- }
- *arg->argval = arg->argvalptr = xstrdup(CSTR(rval));
+ arg.argval->set(rval);
}
void Vecs::disp_vec_options(const QString& vecname, const QVector<arglist_t>* args)
{
if (args) {
for (const auto& arg : *args) {
- if (arg.argval && *arg.argval) {
+ if ((arg.argval != nullptr) && !arg.argval->isEmpty()) {
printf("options: module/option=value: %s/%s=\"%s\"",
- qPrintable(vecname), qPrintable(arg.argstring), *arg.argval);
- if (case_ignore_strcmp(arg.defaultvalue, *arg.argval) == 0) {
+ qPrintable(vecname), qPrintable(arg.argstring), qPrintable(arg.argval->get()));
+ if (case_ignore_strcmp(arg.defaultvalue, arg.argval->get()) == 0) {
printf(" (=default)");
}
printf("\n");
if (!fmtdata.options.isEmpty()) {
const QString opt = get_option(fmtdata.options, arg.argstring);
if (!opt.isNull()) {
- assign_option(fmtdata.fmtname, &arg, opt);
+ assign_option(fmtdata.fmtname, arg, opt);
continue;
}
}
qopt = inifile_readstr(global_opts.inifile, "Common format settings", arg.argstring);
}
if (qopt.isNull()) {
- assign_option(fmtdata.fmtname, &arg, arg.defaultvalue);
+ assign_option(fmtdata.fmtname, arg, arg.defaultvalue);
} else {
- assign_option(fmtdata.fmtname, &arg, qopt);
+ assign_option(fmtdata.fmtname, arg, qopt);
}
}
}
}
#endif
for (const auto& arg : *args) {
+ if (arg.argval == nullptr) {
+ Warning() << name << "option" << arg.argstring << "does not point to an Option instance.";
+ ok = false;
+ }
if ((arg.argtype & ARGTYPE_TYPEMASK) == ARGTYPE_INT) {
if (!arg.defaultvalue.isNull() && !is_integer(arg.defaultvalue)) {
Warning() << name << "Int option" << arg.argstring << "default value" << arg.defaultvalue << "is not an integer.";
Warning() << name << "Bool option" << arg.argstring << "maximum value" << arg.maxvalue << "is not an bool.";
ok = false;
}
+ if (const auto* opt = dynamic_cast<const OptionBool*>(arg.argval); opt == nullptr) {
+ Warning() << name << "Bool option" << arg.argstring << "argval is not of class OptionBool";
+ ok = false;
+ }
+ }
+ if ((arg.argtype & ARGTYPE_TYPEMASK) != ARGTYPE_BOOL) {
+ if (const auto* opt = dynamic_cast<const OptionBool*>(arg.argval); opt != nullptr) {
+ Warning() << name << "non Bool option" << arg.argstring << "argval is of class OptionBool";
+ ok = false;
+ }
}
}
}
static void free_options(QVector<arglist_t>* args);
static void exit_vec(Format* fmt);
void exit_vecs();
- static void assign_option(const QString& module, arglist_t* arg, const QString& val);
+ static void assign_option(const QString& module, arglist_t& arg, const QString& val);
static void disp_vec_options(const QString& vecname, const QVector<arglist_t>* args);
static void validate_options(const QStringList& options, const QVector<arglist_t>* args, const QString& name);
static QString get_option(const QStringList& options, const QString& argname);
fatal(MYNAME ": XCSV input style not declared. Use ... -i xcsv,style=path/to/file.style\n");
}
- xcsv_style = new XcsvStyle(XcsvStyle::xcsv_read_style(styleopt));
+ xcsv_style = new XcsvStyle(XcsvStyle::xcsv_read_style(styleopt.get()));
}
if ((xcsv_style->datatype == 0) || (xcsv_style->datatype == wptdata)) {
fatal(MYNAME ": XCSV output style not declared. Use ... -o xcsv,style=path/to/file.style\n");
}
- xcsv_style = new XcsvStyle(XcsvStyle::xcsv_read_style(styleopt));
+ xcsv_style = new XcsvStyle(XcsvStyle::xcsv_read_style(styleopt.get()));
}
xcsv_file = new XcsvFile;
xcsv_file->mkshort_handle.set_length(xstrtoi(snlenopt, nullptr, 10));
}
- if (snwhiteopt) {
- xcsv_file->mkshort_handle.set_whitespace_ok(xstrtoi(snwhiteopt, nullptr, 10));
+ if (snwhiteopt.has_value()) {
+ xcsv_file->mkshort_handle.set_whitespace_ok(snwhiteopt);
}
- if (snupperopt) {
- xcsv_file->mkshort_handle.set_mustupper(xstrtoi(snupperopt, nullptr, 10));
+ if (snupperopt.has_value()) {
+ xcsv_file->mkshort_handle.set_mustupper(snupperopt);
}
- if (snuniqueopt) {
- xcsv_file->mkshort_handle.set_mustuniq(xstrtoi(snuniqueopt, nullptr, 10));
+ if (snuniqueopt.has_value()) {
+ xcsv_file->mkshort_handle.set_mustuniq(snuniqueopt);
}
xcsv_file->mkshort_handle.set_badchars(CSTR(xcsv_style->badchars));
#include "format.h" // for Format
#include "garmin_fs.h" // for garmin_fs_t
#include "mkshort.h" // for MakeShort
+#include "option.h" // for OptionCString, OptionBool
#include "src/core/datetime.h" // for DateTime
#include "src/core/textstream.h" // for TextStream
const route_head* csv_track = nullptr;
const route_head* csv_route = nullptr;
- char* styleopt = nullptr;
- char* snlenopt = nullptr;
- char* snwhiteopt = nullptr;
- char* snupperopt = nullptr;
- char* snuniqueopt = nullptr;
- char* prefer_shortnames = nullptr;
- char* xcsv_urlbase = nullptr;
- char* opt_datum = nullptr;
- char* opt_utc = nullptr;
+ OptionCString styleopt;
+ OptionCString snlenopt;
+ OptionBool snwhiteopt;
+ OptionBool snupperopt;
+ OptionBool snuniqueopt;
+ OptionBool prefer_shortnames;
+ OptionCString xcsv_urlbase;
+ OptionCString opt_datum;
+ OptionCString opt_utc;
int utc_offset{};
QString intstylefile;